Я использую ftpwebrequest для загрузки некоторых файлов в старую систему мэйнфреймов (MPE / IX), которая у нас есть.
Файл является файлом .prn и, по сути, содержит много записей фиксированной ширины и без разделителя. Каждая запись имеет длину 176 символов и имеет CRLF в конце.
Если для загрузки в виде ASCII-файла выбрать usebinary = false, он создает файл с каждой записью в мейнфрейме, но каждая строка / запись усекается до 80 символов.
Как указать количество символов как 176.
Спасибо!
Это код, который я использую, который, как я уже сказал, передает файл на мэйнфрейм, а затем рассылает электронные письма соответствующим людям.
Public Sub Main()
Dim i As Integer = 1
Dim credential As NetworkCredential
Try
EmailList = ReadEmailAddress()
credential = New NetworkCredential("USERNAME", String.Empty)
FileList.AddRange({"CAN04_30030_", "CAN04_34120_", "CSI01_30030_", "CSI01_34120_"})
For Each FileName In FileList
Dim File As FileInfo
Dim Response As ArrayList
Try
File = New FileInfo(IO.Path.Combine(SourceFileFolder, FileName & Now.ToString("yyyyMMdd") & ".prn"))
If File.Exists Then
Response = ftp.Upload(File, "ftp://SERVERNAME/FILENAME" & i, credential)
UploadResults.Add(Response(1))
Else
UploadResults.Add("<font color=""red"">" & File.Name & " was not found in the folder " & SourceFileFolder & "</font>")
End If
If Not Response Is Nothing Then
If Response(0) = 226 Then ArchiveFile(File)
End If
Catch ex As Exception
UploadResults.Add("<font color=""red"">" & ex.Message & " occurred while trying to upload the file " & File.Name & "</font>")
Finally
File = Nothing
Response = Nothing
End Try
i += 1
Next
SendMail()
Catch ex As Exception
Finally
credential = Nothing
End Try
End Sub
Public Function Upload(ByVal File As FileInfo, ByVal target As String, ByVal credential As NetworkCredential) As ArrayList
Dim AList As New ArrayList
Try
request = DirectCast(WebRequest.Create(target), FtpWebRequest)
With request
.Method = WebRequestMethods.Ftp.UploadFile
.UsePassive = True
.Credentials = credential
.KeepAlive = False
.UseBinary = False
End With
Dim sourceStream As StreamReader = New StreamReader(File.FullName, True)
Dim filecontents() As Byte = Encoding.ASCII.GetBytes(sourceStream.ReadToEnd)
sourceStream.Close()
request.ContentLength = filecontents.Length
Dim stream As Stream = request.GetRequestStream
stream.Write(filecontents, 0, filecontents.Length)
stream.Flush()
stream.Close()
response = DirectCast(request.GetResponse, FtpWebResponse)
Dim t() As String = Split(target, "/")
Try
AList.Add(response.StatusCode)
Catch ex As Exception
AList.Add(String.Empty)
End Try
If response.StatusCode = 226 Then
AList.Add(File.Name & " (" & t(t.GetUpperBound(0)) & ") " & " was transferred to " & UCase(credential.UserName) & " [<i>" & Split(response.StatusDescription, ".")(0) & "</i>]")
Else
AList.Add(File.Name & " (" & t(t.GetUpperBound(0)) & ") " & " was NOT transferred to " & UCase(credential.UserName) & " [<i>" & Split(response.StatusDescription, ".")(0) & "</i>]")
End If
Catch ex As Exception
AList.Add(File.Name & " was NOT transferred. " & ex.Message.ToString)
Finally
response.Close()
request = Nothing
response = Nothing
File = Nothing
End Try
Return AList
End Function