Mickey Sly
Mickey Sly

Reputation: 429

FTP File Not found code 550

I am trying to fix a program that another developer has developed. What I'm trying to fix is everytime the program attempts to upload a file it would return a 'File . not found (code=550)'. The weird thing is that the actual file for some reason would actually upload... When I received a copy of the code to fix I tried the program out myself and it gives me the same error yet the file actually doesn't upload.

The code Imports Utilities.FTP (Which I haven't been able to find a lot of documentation on online..) and the exception is thrown after the ftp.CopyToFTP() is run. CopyToFTP basically copies the file to the FTP site directory you place.

Does anyone have any way to trouble shoot this? or a solution?

Private Sub FtpOutputFile(ByVal atts As List(Of String)) Dim inStream As StreamReader Dim parseLn() As String Dim ftp As New Utilities.FTP.FTP()

    Try

        inStream = New StreamReader(File.OpenRead(Me.Directory & "ftp.dat"))
        'Setup FTP object
        While inStream.EndOfStream = False
            parseLn = Split(inStream.ReadLine(), ",")
            Select Case parseLn(0)
                Case "Destination"
                    ftp.Destination = parseLn(1)
                Case "Expiration"
                    ftp.Expiration = parseLn(1)
                Case "Host"
                    ftp.FTP_Host = parseLn(1)
                Case "Password"
                    ftp.FTP_Password = parseLn(1)
                Case "Timeout"
                    ftp.FTP_Timeout = parseLn(1)
                Case "UserName"
                    ftp.FTP_UserName = parseLn(1)
            End Select
        End While
        inStream.Close()

        Dim MyEnum As IEnumerator(Of String) = atts.GetEnumerator
        While MyEnum.MoveNext                                  'I added this? Before it was just the directory but this would be the entire file?
            ftp.Source = Path.GetDirectoryName(MyEnum.Current) + "\DailyExcel" & DailyDate.ToString("yyyyMMdd") & ".csv"
            If Not ftp.CopyToFTP() Then
                Throw New Exception(ftp.ErrorMessage)
            End If
        End While

    Catch ex As Exception
        Trace.WriteLine(Date.Now.ToString("MM/dd/yyyy HH:mm") & ": " & ex.Message & vbNewLine & ex.StackTrace)
        MsgBox(ex.Message())
    End Try

End Sub

my .dat file is as follows:

Destination,excelfiles/Test/
Expiration,30
Host,myftp.mydomainname.com
Password,password
Timeout,5000
UserName,username

Upvotes: 0

Views: 3633

Answers (3)

THE AMAZING
THE AMAZING

Reputation: 1603

I don't know about all of hat nonsense you coded but a few rules, You should NOT generate a file during the FTP (or any instantiated connection type) you want to keep the live time down to a absolute minimum for security and efficiency reasons.

Essentially, other than the procedural style the coder adapted to there isn't anything else that i can see that is politically wrong with the code.

550 is specifically a Access denied error. And that is not the entire error message, it should also tell you if it is a connection to the server that is being denied or the users credentials.

Your team doesn't seem to familiar with the FTP procedures in VB.net, take a look at my FTP i wrote for a friend.

Public Class FTP
        '-------------------------[BroCode]--------------------------
        '----------------------------FTP-----------------------------
        Private _credentials As System.Net.NetworkCredential
        Sub New(ByVal _FTPUser As String, ByVal _FTPPass As String)
            setCredentials(_FTPUser, _FTPPass)
        End Sub
        Public Sub UploadFile(ByVal _FileName As String, ByVal _UploadPath As String)
            Dim _FileInfo As New System.IO.FileInfo(_FileName)
            Dim _FtpWebRequest As System.Net.FtpWebRequest = CType(System.Net.FtpWebRequest.Create(New Uri(_UploadPath)), System.Net.FtpWebRequest)
            _FtpWebRequest.Credentials = _credentials
            _FtpWebRequest.KeepAlive = False
            _FtpWebRequest.Timeout = 20000
            _FtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
            _FtpWebRequest.UseBinary = True
            _FtpWebRequest.ContentLength = _FileInfo.Length
            Dim buffLength As Integer = 2048
            Dim buff(buffLength - 1) As Byte
            Dim _FileStream As System.IO.FileStream = _FileInfo.OpenRead()
            Try
                Dim _Stream As System.IO.Stream = _FtpWebRequest.GetRequestStream()
                Dim contentLen As Integer = _FileStream.Read(buff, 0, buffLength)
                Do While contentLen <> 0
                    _Stream.Write(buff, 0, contentLen)
                    contentLen = _FileStream.Read(buff, 0, buffLength)
                Loop
                _Stream.Close()
                _Stream.Dispose()
                _FileStream.Close()
                _FileStream.Dispose()
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Upload Error: ", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub
        Public Sub DownloadFile(ByVal _FileName As String, ByVal _ftpDownloadPath As String)
            Try
                Dim _request As System.Net.FtpWebRequest = System.Net.WebRequest.Create(_ftpDownloadPath)
                _request.KeepAlive = False
                _request.Method = System.Net.WebRequestMethods.Ftp.DownloadFile
                _request.Credentials = _credentials
                Dim _response As System.Net.FtpWebResponse = _request.GetResponse()
                Dim responseStream As System.IO.Stream = _response.GetResponseStream()
                Dim fs As New System.IO.FileStream(_FileName, System.IO.FileMode.Create)
                responseStream.CopyTo(fs)
                responseStream.Close()
                _response.Close()
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Download Error: ", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub
        Public Function GetDirectory(ByVal _ftpPath As String) As List(Of String)
            Dim ret As New List(Of String)
            Try
                Dim _request As System.Net.FtpWebRequest = System.Net.WebRequest.Create(_ftpPath)
                _request.KeepAlive = False
                _request.Method = System.Net.WebRequestMethods.Ftp.ListDirectoryDetails
                _request.Credentials = _credentials
                Dim _response As System.Net.FtpWebResponse = _request.GetResponse()
                Dim responseStream As System.IO.Stream = _response.GetResponseStream()
                Dim _reader As System.IO.StreamReader = New System.IO.StreamReader(responseStream)
                Dim FileData As String = _reader.ReadToEnd
                Dim Lines() As String = FileData.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
                For Each l As String In Lines
                    ret.Add(l)
                Next
                _reader.Close()
                _response.Close()
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Directory Fetch Error: ", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
            Return ret
        End Function

        Private Sub setCredentials(ByVal _FTPUser As String, ByVal _FTPPass As String)
            _credentials = New System.Net.NetworkCredential(_FTPUser, _FTPPass)
        End Sub
    End Class

Upvotes: 0

Mickey Sly
Mickey Sly

Reputation: 429

Thanks to Sam Makin I was able to figure out the error. It seemed the file would download all data from an FTP directory and delete any files with a last modified date of over 30 days ago. If it wasn't it added it to a array to be compared to which was cross referenced with a local directory to determine what files should be uploaded.

The problem is when it downloaded all files it included the files '.' and '..' Which from what I know I'm going to assume that means current directory and parent directory. So it would see that the directory was created awhile ago attempt to delete it and it would say that the file wasn't found.

Upvotes: 0

Sam Makin
Sam Makin

Reputation: 1556

FTP error code 550 is access denied. Are you sure the server is configured properly?

Upvotes: 0

Related Questions