2016-12-23 225 views
2

當前我編程上試圖上傳文件到使用WinSCP API的服務器。WinSCP錯誤「沒有這樣的文件」,當上傳文件到服務器

但是,每次嘗試執行此操作時都會查看日誌文件,我收到一條錯誤消息,指出遠程文件或其目錄不存在。

代碼:

Dim objftp As New WinSCP.SessionOptions 
objftp.HostName = Server 
objftp.PortNumber = Port 
objftp.Protocol = Protocol.Sftp 
objftp.UserName = User 
objftp.Password = Password 
objftp.PrivateKeyPassphrase = "passPhrase" 
objftp.SshPrivateKeyPath = "\\PathToPrivatekey.ppk" 
objftp.GiveUpSecurityAndAcceptAnySshHostKey = True 

Dim session As New Session 

session.Timeout = System.TimeSpan.FromSeconds(30) 
session.SessionLogPath = "C:\Temp\ftpLog\winscp.log" 
session.Open(objFTP) 

Dim transferOptions As New TransferOptions 

transferOptions.TransferMode = TransferMode.Binary 
transferOptions.ResumeSupport.State = TransferResumeSupportState.Off 
Dim transferResult As TransferOperationResult 

strLocalFile = FilePath & FileName 
strRemoteFile = FileName 
transferResult = session.PutFiles(strLocalFile, "/In/", False, transferOptions) 

transferResult.Check() 

session.Close() 

現在我已經使用手動的WinSCP連接到服務器,我可以確認/In/目錄確實存在。我正在使用Windows操作系統來執行此操作。我沒有關於服務器的完整詳細信息,因爲它是我發送信息的第三方。

在我的代碼中是否存在缺少的東西?

編輯:根據要求,這是我的日誌:從編程嘗試它

登錄:

. 2016-12-23 10:52:07.089 -------------------------------------------------------------------------- 
. 2016-12-23 10:52:07.089 WinSCP Version 5.9.3 (Build 7136) (OS 6.1.7601 Service Pack 1 - Windows 7 Professional) 
. 2016-12-23 10:52:07.089 Configuration: nul 
. 2016-12-23 10:52:07.089 Log level: Normal 
. 2016-12-23 10:52:07.089 Local account: user\Andrew 
. 2016-12-23 10:52:07.089 Working directory: \\WorkingDIr\ 
. 2016-12-23 10:52:07.089 Process ID: 12648 
. 2016-12-23 10:52:07.090 Command-line: "\\WorkingDir\winscp.exe" /xmllog="C:\Users\andrew\AppData\Local\Temp\wscp46E9.02B7AFA0.tmp" /xmlgroups /xmllogrequired /nointeractiveinput /dotnet=593 /ini=nul /log="C:\Temp\ftpLog\winscp.log" /console /consoleinstance=_10192_57352375_875 
. 2016-12-23 10:52:07.090 Time zone: Current: GMT+0, Standard: GMT+0 (GMT Standard Time), DST: GMT+1 (GMT Daylight Time), DST Start: 27/03/2016, DST End: 30/10/2016 
. 2016-12-23 10:52:07.090 Login time: 23 December 2016 10:52:07 
. 2016-12-23 10:52:07.090 -------------------------------------------------------------------------- 
. 2016-12-23 10:52:07.094 Script: Retrospectively logging previous script records: 
> 2016-12-23 10:52:07.094 Script: option batch on 
< 2016-12-23 10:52:07.094 Script: batch   on   
< 2016-12-23 10:52:07.094 Script: reconnecttime 120  
> 2016-12-23 10:52:07.094 Script: option confirm off 
< 2016-12-23 10:52:07.094 Script: confirm   off  
> 2016-12-23 10:52:07.094 Script: option reconnecttime 120 
< 2016-12-23 10:52:07.094 Script: reconnecttime 120  
> 2016-12-23 10:52:07.094 Script: open sftp://user:***@server.com:22 -hostkey="*" -privatekey="\\containingDir\PrivateKey.ppk" -passphrase=*** -timeout=15 
. 2016-12-23 10:52:07.094 -------------------------------------------------------------------------- 
. 2016-12-23 10:52:07.094 Session name: [email protected] (Ad-Hoc site) 
. 2016-12-23 10:52:07.094 Host name: server.com (Port: 22) 
. 2016-12-23 10:52:07.095 User name: user(Password: Yes, Key file: Yes, Passphrase: Yes) 
. 2016-12-23 10:52:07.095 Tunnel: No 
. 2016-12-23 10:52:07.095 Transfer Protocol: SFTP 
. 2016-12-23 10:52:07.095 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec 
. 2016-12-23 10:52:07.095 Disable Nagle: No 
. 2016-12-23 10:52:07.095 Proxy: None 
. 2016-12-23 10:52:07.095 Send buffer: 262144 
. 2016-12-23 10:52:07.095 SSH protocol version: 2; Compression: No 
. 2016-12-23 10:52:07.095 Bypass authentication: No 
. 2016-12-23 10:52:07.095 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No 
. 2016-12-23 10:52:07.095 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No 
. 2016-12-23 10:52:07.095 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1 
. 2016-12-23 10:52:07.095 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto 
. 2016-12-23 10:52:07.095 Simple channel: Yes 
. 2016-12-23 10:52:07.095 Return code variable: Autodetect; Lookup user groups: Auto 
. 2016-12-23 10:52:07.095 Shell: default 
. 2016-12-23 10:52:07.095 EOL: LF, UTF: Auto 
. 2016-12-23 10:52:07.095 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No 
. 2016-12-23 10:52:07.095 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No 
. 2016-12-23 10:52:07.095 SFTP Bugs: Auto,Auto 
. 2016-12-23 10:52:07.095 SFTP Server: default 
. 2016-12-23 10:52:07.095 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes 
. 2016-12-23 10:52:07.095 Cache directory changes: Yes, Permanent: Yes 
. 2016-12-23 10:52:07.095 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2016-12-23 10:52:07.095 DST mode: Unix 
. 2016-12-23 10:52:07.095 -------------------------------------------------------------------------- 
. 2016-12-23 10:52:07.106 Looking up host "server.com" for SSH connection 
. 2016-12-23 10:52:07.126 Connecting to 11.11.11.11 port 22 
. 2016-12-23 10:52:07.307 We claim version: SSH-2.0-WinSCP_release_5.9.3 
. 2016-12-23 10:52:07.496 Server version: SSH-2.0-9.99 sshlib: 8.1.0.0 
. 2016-12-23 10:52:07.496 We believe remote version has SSH-2 channel request bug 
. 2016-12-23 10:52:07.496 Using SSH protocol version 2 
. 2016-12-23 10:52:07.504 Doing Diffie-Hellman group exchange 
. 2016-12-23 10:52:07.928 Doing Diffie-Hellman key exchange with hash SHA-1 
. 2016-12-23 10:52:08.307 Host key fingerprint is: 
. 2016-12-23 10:52:08.307 ssh-rsa fingerprint 
. 2016-12-23 10:52:08.308 Verifying host key host key 
* 2016-12-23 10:52:08.308 WARNING! Giving up security and accepting any host key as configured! 
. 2016-12-23 10:52:08.310 Initialised AES-256 SDCTR client->server encryption 
. 2016-12-23 10:52:08.310 Initialised HMAC-SHA1 client->server MAC algorithm 
. 2016-12-23 10:52:08.310 Initialised AES-256 SDCTR server->client encryption 
. 2016-12-23 10:52:08.310 Initialised HMAC-SHA1 server->client MAC algorithm 
. 2016-12-23 10:52:08.741 Reading key file "\\PrivateKseyDir\PrivateKey.ppk" 
. 2016-12-23 10:52:08.764 Pageant is running. Requesting keys. 
. 2016-12-23 10:52:08.766 Pageant has 0 SSH-2 keys 
. 2016-12-23 10:52:08.766 Configured key file not in Pageant 
! 2016-12-23 10:52:08.766 Using username "user". 
. 2016-12-23 10:52:08.958 Server offered these authentication methods: publickey,password 
. 2016-12-23 10:52:08.958 Offered public key 
. 2016-12-23 10:52:09.193 Offer of public key accepted 
! 2016-12-23 10:52:09.193 Authenticating with public key "rsa-key-20161222" 
. 2016-12-23 10:52:09.194 Prompt (passphrase, "SSH key passphrase", <no instructions>, "Passphrase for key "rsa-key-20161222": ") 
. 2016-12-23 10:52:09.194 Using configured passphrase. 
. 2016-12-23 10:52:09.316 Sent public key signature 
! 2016-12-23 10:52:09.504 Server refused public-key signature despite accepting key! 
. 2016-12-23 10:52:09.504 Server refused public-key signature despite accepting key! 
. 2016-12-23 10:52:09.504 Server offered these authentication methods: password 
. 2016-12-23 10:52:09.504 Prompt (password, "SSH password", <no instructions>, "&Password: ") 
. 2016-12-23 10:52:09.504 Using stored password. 
. 2016-12-23 10:52:09.505 Sent password 
. 2016-12-23 10:52:09.831 Access granted 
. 2016-12-23 10:52:09.831 Opening session as main channel 
. 2016-12-23 10:52:10.017 Opened main channel 
. 2016-12-23 10:52:10.426 Started a shell/command 
. 2016-12-23 10:52:10.426 -------------------------------------------------------------------------- 
. 2016-12-23 10:52:10.432 Using SFTP protocol. 
. 2016-12-23 10:52:10.432 Doing startup conversation with host. 
> 2016-12-23 10:52:10.441 Type: SSH_FXP_INIT, Size: 5, Number: -1 
< 2016-12-23 10:52:10.631 Type: SSH_FXP_VERSION, Size: 5, Number: -1 
. 2016-12-23 10:52:10.631 SFTP version 3 negotiated. 
. 2016-12-23 10:52:10.631 We believe the server has signed timestamps bug 
. 2016-12-23 10:52:10.631 We will use UTF-8 strings until server sends an invalid UTF-8 string as with SFTP version 3 and older UTF-8 strings are not mandatory 
. 2016-12-23 10:52:10.635 Getting current directory name. 
. 2016-12-23 10:52:10.639 Getting real path for '.' 
> 2016-12-23 10:52:10.639 Type: SSH_FXP_REALPATH, Size: 10, Number: 16 
< 2016-12-23 10:52:10.825 Type: SSH_FXP_NAME, Size: 43, Number: 16 
. 2016-12-23 10:52:10.825 Real path is '/Home/user' 
. 2016-12-23 10:52:10.825 Startup conversation with host finished. 
< 2016-12-23 10:52:10.826 Script: Active session: [1] server.com 
> 2016-12-23 10:52:11.141 Script: pwd 
< 2016-12-23 10:52:11.141 Script: /Home/user 
> 2016-12-23 10:52:26.491 Script: put -nopermissions -preservetime -transfer="binary" -resumesupport="off" -- "\\fileDir\testFile.dat" "/In/testFile.dat" 
. 2016-12-23 10:52:26.497 Copying 1 files/directories to remote directory "/In/" 
. 2016-12-23 10:52:26.497 PrTime: Yes; PrRO: No; Rght: rw-r--r--; PrR: No (No); FnCs: N; RIC: 0100; Resume: N (102400); CalcS: No; Mask: testFile.dat 
. 2016-12-23 10:52:26.497 TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0 
. 2016-12-23 10:52:26.497 AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml 
. 2016-12-23 10:52:26.502 File: '\\fileDir\testFile.dat' [2016-12-23T06:31:02.639Z] [212952] 
. 2016-12-23 10:52:26.504 Copying "\\fileDir\testFile.dat" to remote directory started. 
. 2016-12-23 10:52:26.504 Binary transfer mode selected. 
. 2016-12-23 10:52:26.505 Opening remote file. 
> 2016-12-23 10:52:26.509 Type: SSH_FXP_OPEN, Size: 50, Number: 259 
< 2016-12-23 10:52:26.681 Type: SSH_FXP_STATUS, Size: 31, Number: 259 
< 2016-12-23 10:52:26.681 Status code: 2, Message: 259, Server: No such file, Language: en 
> 2016-12-23 10:52:26.681 Type: SSH_FXP_LSTAT, Size: 34, Number: 519 
< 2016-12-23 10:52:26.849 Type: SSH_FXP_STATUS, Size: 31, Number: 519 
< 2016-12-23 10:52:26.849 Status code: 2, Message: 519, Server: No such file, Language: en 
* 2016-12-23 10:52:26.849 (ETerminal) No such file or directory. 
* 2016-12-23 10:52:26.849 Error code: 2 
* 2016-12-23 10:52:26.849 Error message from server (en): No such file 
. 2016-12-23 10:52:26.850 Asking user: 
. 2016-12-23 10:52:26.850 Cannot create remote file '/In/testFile.dat'. ("No such file or directory. 
. 2016-12-23 10:52:26.850 Error code: 2 
. 2016-12-23 10:52:26.850 Error message from server (en): No such file") 
< 2016-12-23 10:52:26.850 Script: Cannot create remote file '/In/testFile.dat'. 
< 2016-12-23 10:52:26.850 Script: No such file or directory. 
< 2016-12-23 10:52:26.850 Error code: 2 
< 2016-12-23 10:52:26.850 Error message from server (en): No such file 
* 2016-12-23 10:52:26.862 (EScpSkipFile) Cannot create remote file '/In/testFile.dat'. 
* 2016-12-23 10:52:26.862 No such file or directory. 
* 2016-12-23 10:52:26.862 Error code: 2 
* 2016-12-23 10:52:26.862 Error message from server (en): No such file 
. 2016-12-23 10:52:26.862 Script: Failed 

這是從我的日誌與GUI成功地做這件事:

> 2016-12-23 10:59:12.037 Type: SSH_FXP_SETSTAT, Size: 54, Number: 2057 
< 2016-12-23 10:59:12.221 Type: SSH_FXP_STATUS, Size: 40, Number: 2057 
< 2016-12-23 10:59:12.221 Status code: 8, Message: 2057, Server: Operation unsupported, Language: en 
* 2016-12-23 10:59:12.222 (ETerminal) The server does not support the operation. 
* 2016-12-23 10:59:12.222 Error code: 8 
* 2016-12-23 10:59:12.222 Error message from server (en): Operation unsupported 
. 2016-12-23 10:59:12.226 Asking user: 
. 2016-12-23 10:59:12.226 **Upload of file 'sftpTest.dat' was successful, but error occurred while setting the permissions and/or timestamp.** 
. 2016-12-23 10:59:12.226 
. 2016-12-23 10:59:12.226 If the problem persists, turn off setting permissions or preserving timestamp. Alternatively you can turn on 'Ignore permission errors' option. ("The server does not support the operation. 
. 2016-12-23 10:59:12.226 Error code: 8 
. 2016-12-23 10:59:12.226 Error message from server (en): Operation unsupported") 
* 2016-12-23 10:59:14.385 (EScpSkipFile) **Upload of file 'sftpTest.dat' was successful, but error occurred while setting the permissions and/or timestamp.** 
* 2016-12-23 10:59:14.385 
* 2016-12-23 10:59:14.385 If the problem persists, turn off setting permissions or preserving timestamp. Alternatively you can turn on 'Ignore permission errors' option. 
* 2016-12-23 10:59:14.385 The server does not support the operation. 
* 2016-12-23 10:59:14.385 Error code: 8 
* 2016-12-23 10:59:14.385 Error message from server (en): Operation unsupported 
. 2016-12-23 10:59:14.386 Listing directory "/Home/user". 
> 2016-12-23 10:59:14.386 Type: SSH_FXP_OPENDIR, Size: 20, Number: 4875 
< 2016-12-23 10:59:14.602 Type: SSH_FXP_HANDLE, Size: 13, Number: 4875 
> 2016-12-23 10:59:14.603 Type: SSH_FXP_READDIR, Size: 13, Number: 5132 
< 2016-12-23 10:59:14.817 Type: SSH_FXP_NAME, Size: 245, Number: 5132 
> 2016-12-23 10:59:14.817 Type: SSH_FXP_READDIR, Size: 13, Number: 5388 
< 2016-12-23 10:59:15.022 Type: SSH_FXP_STATUS, Size: 30, Number: 5388 
< 2016-12-23 10:59:15.022 Status code: 1 
> 2016-12-23 10:59:15.022 Type: SSH_FXP_CLOSE, Size: 13, Number: 5636 
. 2016-12-23 10:59:15.022 In;d;0;2016-12-20T15:48:00.000Z;"0" [0];"0" [0];rwxrwxrwx;1 
. 2016-12-23 10:59:15.022 sftpTest.dat;-;212952;2016-12-23T10:59:00.000Z;"0" [0];"0" [0];rw-rw-rw-;1 
+1

向我們顯示一條確切的錯誤消息,甚至更好的日誌文件。 +向我們展示一個WinSCP GUI日誌文件,顯示如何(成功)將同一文件上傳到同一個遠程目錄。 –

+0

在那裏添加日誌記錄 –

+0

請發佈完整的日誌。這根本沒有幫助。 –

回答

0

Documentation將討論遠程文件的完整路徑,而不是包含該文件的目錄。你可以嘗試指定完整路徑:

transferResult = session.PutFiles(strLocalFile, "/In/remote_file.ext", False, transferOptions) 
+0

我確實試過了,但不幸的是,這又回到了同樣的問題。 –

+0

我有記錄,它返回以下內容: <2016-12-23 10:52:26.849狀態碼:2,消息:519,服務器:沒有這樣的文件,語言:en * 2016-12-23 10: 52:26.849(ETerminal)沒有這樣的文件或目錄。 * 2016-12-23 10:52:26.849錯誤代碼:2 * 2016-12-23 10:52:26.849來自服務器(en)的錯誤消息:沒有該文件 。 2016-12-23 10:52:26.850問問用戶: 。 2016-12-23 10:52:26.850無法創建遠程文件'/In/sftpTest.dat'。 (「沒有這樣的文件或目錄 –

2

雖然我不能告訴是肯定的,因爲你沒有提供足夠的信息,我的猜測是,你真正的目標路徑應/Home/user/In/,不只是/In/

從GUI日誌看來,您的帳戶似乎不是chrooted,因爲主目錄是/Home/user/,而不是/

. 2016-12-23 10:59:14.386 Listing directory "/Home/user". 
+0

非常感謝你的幫助,這是問題,希望你有一個愉快的假期!! –

+0

不客氣,雖然在堆棧溢出我們[感謝接受答案](http ://stackoverflow.com/help/someone-answers)。 –

相關問題