2014-03-31 68 views
0

我正在修復另一個開發人員開發的程序。我試圖解決的問題是,每次程序嘗試上傳文件時,都會返回一個「文件」。未找到(代碼= 550)'。奇怪的是,由於某種原因,實際上的文件實際上傳了......當我收到一個修復代碼的副本時,我自己嘗試了這個程序,它給了我同樣的錯誤,但是這個文件實際上沒有上傳。FTP文件未找到代碼550

代碼Imports Utilities.FTP(我沒有能夠在網上找到很多文檔..),並且在運行ftp.CopyToFTP()之後拋出異常。 CopyToFTP基本上將文件複製到您放置的FTP站點目錄。

有沒有人有任何方法來解決這個問題?或解決方案?

私人小組FtpOutputFile(BYVAL的ATT方式列表(串)) 昏暗inStream中作爲StreamReader的 昏暗parseLn()作爲字符串 昏暗的FTP作爲新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 

我。 dat文件如下:

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

如果你沒有爲CopyToFTP方法的代碼,你可能會反映裝配 - http://ilspy.net/ –

+0

謝謝你的提示。我能夠更好地理解該方法的效果,它比較了源目錄和FTP目錄,然後將FTP目錄中不存在的文件複製到FTP目錄 –

回答

0

感謝Sam Makin我能弄清楚錯誤。看起來該文件將從FTP目錄下載所有數據,並刪除最近修改日期超過30天前的任何文件。如果不是,則將其添加到數組中以與本地目錄進行交叉引用進行比較,以確定應該上傳哪些文件。

問題是當它下載所有包含文件''的文件時。和'..'從我知道的我將假設這意味着當前目錄和父目錄。所以它會看到該目錄是在前一段時間創建的,試圖刪除它,並且它會說沒有找到該文件。

+0

不可能,如果你收到一個550.看看這個線程,http://stackoverflow.com/questions/10813700/vb-net-ftp-error-550 –

0

FTP錯誤代碼550是訪問被拒絕。你確定服務器配置正確嗎?

+0

我問了很多......顯然,服務器最近大約一個月前轉換,我會說這些問題可能在同一時間出現。添加測試文件夾,並給它完整的權限,但仍然存在相同的問題....除此之外,還有什麼可以配置不當會導致此錯誤? –

+0

問題在於550.錯誤與您的連接有關。 –

0

我不知道你編碼的所有帽子廢話,但有幾條規則, 你不應該在FTP(或任何實例化的連接類型)期間生成一個文件,以便將實時時間降至最低出於安全和效率的原因。

從本質上講,除了程序風格的編碼器適應於沒有任何其他的,我可以看到在代碼在政治上是錯誤的。

550具體是一個Access拒絕錯誤。這並不是完整的錯誤信息,它也應該告訴你它是否是連接到被拒絕的服務器或用戶憑證。

你的團隊似乎並不熟悉VB.net中的FTP程序,看看我爲朋友寫的FTP。

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 
相關問題