2016-04-23 122 views

回答

1

有幾件事你可以做。你可以創建一個會話日誌,告訴你(在很多細節上)你的文件傳輸過程中發生了什麼。您還可以在mySession.Open(mySessionOptions)附近放置一個try-catch塊來捕獲錯誤。

最後,使用mySession.FileExists(remotepath)來檢查,看看是否該文件已經在服務器上。

Dim mySessionOptions As New SessionOptions 
With mySessionOptions 
    .Protocol = Protocol.Sftp 
    .HostName = "999.999.999.999" 
    .UserName = "login" 
    .Password = "mypassword" 
    .SshHostKeyFingerprint = "ssh-dss 1024 99:87:99:4d:99:a3:99:b9:99:15:99:f2:99:87:88:b2" 
End With 

Using mySession As Session = New Session 
    ' Will continuously report progress of synchronization 
    AddHandler mySession.FileTransferred, AddressOf FileTransferred 

    ' Connect 
    mySession.SessionLogPath = "C:\Users\yourName\yourFolder\Sessionlog.log" 

    'Use Try-Catch to check for error in connection 
    Try 
     mySession.Open(mySessionOptions) 
    Catch ex As Exception 
     MessageBox.show(ex.Message) 
     mySession.Close() 
     Exit Sub 
    End Try 

    'Check to see if file exist already on server 
    If mySession.FileExists(remotePath) Then 
      MessageBox.Show("File Exists on Server") 
      mySession.Close() 
      Exit Sub 
    End If 

    mySession.PutFiles("C:\Users\yourName\yourFolder\yourfile.dat", remotePath) 

    mySession.Close() 

End Using 

請記住檢查您創建的日誌,以確切瞭解發生了什麼。

+0

您還需要測試'PutFiles'是否成功。使用'.Check()'。例如:'mySession.PutFiles(「C:\ Users \ yourName \ yourFolder \ yourfile.dat」,remotePath).Check()'。請參閱[捕獲操作結果](https://winscp.net/eng/docs/library_session#results)。 –

相關問題