Link to home
Start Free TrialLog in
Avatar of pprater1
pprater1

asked on

FTP upload to OpenVMS using VB.NET

I am attempting to FTP a file with a specific format to an OpenVMS system, using the VB.NET FtpWebRequest object (see code snippet).  The strExportText string is given a value by opening a .txt file and reading in the contents.  The text file contains 3 lines of text.  The code below will successfully make the connection, stream the bytes, and end the connection.  When the file is opened on the OpenVMS side, the carriage returns are not being recognized.  There should be 3 lines of text, where now there is one continuous line with the letters CR and LF at the carriage return and line feed positions.  What settings need to be set in order for the OpenVMS to understand the characters?
Private Function ExportShipped(ByVal strExportText As String) As DBReturn
        Dim dbrReturn As DBReturn = DBReturn.Fail
        Dim ftpReq As FtpWebRequest
        Dim ftpStream As IO.Stream
        Dim bytExportText(strExportText.Length) As Byte
        Dim sdrSOExportInfo As SqlDataReader
        Dim strFTPDirectory As String
        Dim strFileName As String
        Dim strUserName As String
        Dim strPassword As String
        
        Try
            sdrSOExportInfo = mobjDBShipping.GetSOExportInfo()
            If sdrSOExportInfo.Read Then
                strFTPDirectory = sdrSOExportInfo(db_Shipping.SOExportIX.OutputDirectory).ToString
                strFileName = sdrSOExportInfo(db_Shipping.SOExportIX.OutputFileName).ToString
                strUserName = sdrSOExportInfo(db_Shipping.SOExportIX.Username).ToString
                strPassword = sdrSOExportInfo(db_Shipping.SOExportIX.Password).ToString
 
                ftpReq = FtpWebRequest.Create(strFTPDirectory & "\" & strFileName)
                ftpReq.Credentials = New NetworkCredential(strUserName, strPassword)
                ftpReq.Method = WebRequestMethods.Ftp.UploadFile
	       ftpReq.UseBinary = True
 
                bytExportText = Encoding.Default.GetBytes(strExportText)
                ftpReq.ContentLength = bytExportText.Length
 
                ftpStream = ftpReq.GetRequestStream
                ftpStream.Write(bytExportText, 0, bytExportText.Length)
                ftpStream.Close()
 
                'ftpResponse = ftpReq.GetResponse()
 
                '("Upload File Complete, status {0}", ftpResponse.StatusDescription)
 
                '  ftpResponse.Close()
                dbrReturn = DBReturn.Success
 
            Else
                dbrReturn = DBReturn.Fail
            End If
 
        Catch ex As Exception
            Throw ex
        End Try
 
        Return dbrReturn
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jmfairchild
jmfairchild

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pprater1
pprater1

ASKER

I ended up trying this before you posted and it is absolutely correct.  I used a combination of setting UseBinary = False and the Encoding in line #25 to ASCII.  Not exactly sure why it wanted straight text instead of binary, but it worked.  Thanks for your help!!