Topic "Can't get attributes of file - VB.Net"

Author Message
TonyL

Guest


Having a problem getting this to work in Visual Studio 2013 (VB.NET). I can access the file through main WinSCP.exe (5.7.2.5316) but not able to do so though VS. I'm attempting to Get files from our company SFTP location from external sources and transfer the file to another location where I then process the data received.

Here is my VB code.

Imports WinSCP

Private Sub sbSFTPTransfer(strHostName As String, strUserName As String, strPwd As String)
Dim objSession As Session
Dim objSessionOptions As New SessionOptions
Dim objTransferOptions As New TransferOptions
Dim strFullFileName As String = String.Empty
Dim objTransferResult As TransferOperationResult
Try
' Setup session options
With objSessionOptions
.Protocol = Protocol.Sftp
.HostName = strHostName
.UserName = strUserName
.Password = strPwd
.SshHostKeyFingerprint = strFTPImportServerKey
End With
objSession = New Session
objSession.SessionLogPath = "LogFile.txt"
objSession.Open(objSessionOptions)
' Upload files
With objTransferOptions
.TransferMode = TransferMode.Binary
.PreserveTimestamp = False
.ResumeSupport.State = TransferResumeSupportState.Off
End With
objTransferResult = objSession.GetFiles(strHostName, strFTPImportFolder & "pnmpyt.txt", False, objTransferOptions)
'' Throw on any error
objTransferResult.Check()
Catch MyException As System.Exception
Finally
End Try
End Sub

Here is my log file (modified to remove Key file information):

. 2015-04-15 09:28:54.456 --------------------------------------------------------------------------
. 2015-04-15 09:28:54.456 WinSCP Version 5.7.2 (Build 5316) (OS 6.1.7601 Service Pack 1 - Windows 7 Enterprise)
. 2015-04-15 09:28:54.456 Configuration: nul
. 2015-04-15 09:28:54.456 Log level: Normal
. 2015-04-15 09:28:54.456 Local account: domain\user
. 2015-04-15 09:28:54.456 Working directory: x
. 2015-04-15 09:28:54.456 Process ID: 7968
. 2015-04-15 09:28:54.456 Command-line: x /xmlgroups /nointeractiveinput /dotnet=572 /ini=nul /log="LogFile.txt" /console /consoleinstance=_6628_63125272_685
. 2015-04-15 09:28:54.456 Time zone: Current: GMT-6, Standard: GMT-7 (Mountain Standard Time), DST: GMT-6 (Mountain Daylight Time), DST Start: 3/8/2015, DST End: 11/1/2015
. 2015-04-15 09:28:54.456 Login time: Wednesday, April 15, 2015 9:28:54 AM
. 2015-04-15 09:28:54.456 --------------------------------------------------------------------------
. 2015-04-15 09:28:54.456 Script: Retrospectively logging previous script records:
> 2015-04-15 09:28:54.456 Script: option batch on
< 2015-04-15 09:28:54.456 Script: batch on
< 2015-04-15 09:28:54.456 Script: reconnecttime 120
> 2015-04-15 09:28:54.456 Script: option confirm off
< 2015-04-15 09:28:54.456 Script: confirm off
> 2015-04-15 09:28:54.456 Script: option reconnecttime 120
< 2015-04-15 09:28:54.456 Script: reconnecttime 120
> 2015-04-15 09:28:54.456 Script: open sftp://Name-City:***@sftp%3A%2F%2FName-City%2Fpnmpyt.txt%40Server01 -hostkey="ssh-rsa x" -timeout=15
. 2015-04-15 09:28:54.456 --------------------------------------------------------------------------
. 2015-04-15 09:28:54.456 Session name: Name-City@Server01 (Ad-Hoc site)
. 2015-04-15 09:28:54.456 Host name: Server01 (Port: 22)
. 2015-04-15 09:28:54.456 User name: Name-City(Password: Yes, Key file: No)
. 2015-04-15 09:28:54.456 Tunnel: No
. 2015-04-15 09:28:54.456 Transfer Protocol: SFTP
. 2015-04-15 09:28:54.456 Ping type: -, Ping interval: 30 sec; Timeout: 15 sec
. 2015-04-15 09:28:54.456 Disable Nagle: No
. 2015-04-15 09:28:54.456 Proxy: none
. 2015-04-15 09:28:54.456 Send buffer: 262144
. 2015-04-15 09:28:54.456 SSH protocol version: 2; Compression: No
. 2015-04-15 09:28:54.456 Bypass authentication: No
. 2015-04-15 09:28:54.456 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
. 2015-04-15 09:28:54.456 Ciphers: aes,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2015-04-15 09:28:54.456 KEX: dh-gex-sha1,dh-group14-sha1,dh-group1-sha1,rsa,WARN
. 2015-04-15 09:28:54.456 SSH Bugs: A,A,A,A,A,A,A,A,A,A,A
. 2015-04-15 09:28:54.456 Simple channel: Yes
. 2015-04-15 09:28:54.456 Return code variable: Autodetect; Lookup user groups: A
. 2015-04-15 09:28:54.456 Shell: default
. 2015-04-15 09:28:54.456 EOL: 0, UTF: 2
. 2015-04-15 09:28:54.456 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes
. 2015-04-15 09:28:54.456 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2015-04-15 09:28:54.456 SFTP Bugs: A,A
. 2015-04-15 09:28:54.456 SFTP Server: default
. 2015-04-15 09:28:54.456 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2015-04-15 09:28:54.456 Cache directory changes: Yes, Permanent: Yes
. 2015-04-15 09:28:54.456 DST mode: 1
. 2015-04-15 09:28:54.456 --------------------------------------------------------------------------
. 2015-04-15 09:28:54.456 Looking up host "Server01"
. 2015-04-15 09:28:54.456 Connecting to 172.31.40.70 port 22
. 2015-04-15 09:28:54.472 Server version: SSH-2.0-5.25 FlowSsh: Bitvise SSH Server (WinSSHD) 6.07
. 2015-04-15 09:28:54.472 Using SSH protocol version 2
. 2015-04-15 09:28:54.472 We claim version: SSH-2.0-WinSCP_release_5.7.2
. 2015-04-15 09:28:54.472 Doing Diffie-Hellman group exchange
. 2015-04-15 09:28:54.675 Doing Diffie-Hellman key exchange with hash SHA-256
. 2015-04-15 09:28:54.862 Verifying host key x
. 2015-04-15 09:28:54.862 Host key matches configured key
. 2015-04-15 09:28:54.862 Host key fingerprint is:
. 2015-04-15 09:28:54.862 ssh-rsa x
. 2015-04-15 09:28:54.862 Initialised AES-256 SDCTR client->server encryption
. 2015-04-15 09:28:54.862 Initialised HMAC-SHA-256 client->server MAC algorithm
. 2015-04-15 09:28:54.862 Initialised AES-256 SDCTR server->client encryption
. 2015-04-15 09:28:54.862 Initialised HMAC-SHA-256 server->client MAC algorithm
! 2015-04-15 09:28:55.080 Using username "Name-City".
. 2015-04-15 09:28:55.096 Prompt (password, "SSH password", <no instructions>, "&Password: ")
. 2015-04-15 09:28:55.096 Using stored password.
. 2015-04-15 09:28:55.114 Sent password
. 2015-04-15 09:28:55.114 Access granted
. 2015-04-15 09:28:55.114 Opening session as main channel
. 2015-04-15 09:28:55.114 Opened main channel
. 2015-04-15 09:28:55.364 Started a shell/command
. 2015-04-15 09:28:55.364 --------------------------------------------------------------------------
. 2015-04-15 09:28:55.364 Using SFTP protocol.
. 2015-04-15 09:28:55.364 Doing startup conversation with host.
> 2015-04-15 09:28:55.364 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2015-04-15 09:28:55.364 Type: SSH_FXP_VERSION, Size: 22, Number: -1
. 2015-04-15 09:28:55.364 SFTP version 6 negotiated.
. 2015-04-15 09:28:55.364 Server requests EOL sequence "\r\n".
. 2015-04-15 09:28:55.364 We will use UTF-8 strings as it is mandatory with SFTP version 4 and newer
. 2015-04-15 09:28:55.364 Getting current directory name.
. 2015-04-15 09:28:55.364 Getting real path for '.'
> 2015-04-15 09:28:55.364 Type: SSH_FXP_REALPATH, Size: 11, Number: 16
< 2015-04-15 09:28:55.364 Type: SSH_FXP_NAME, Size: 75, Number: 16
. 2015-04-15 09:28:55.364 Real path is '/'
. 2015-04-15 09:28:55.364 Startup conversation with host finished.
< 2015-04-15 09:28:55.364 Script: Active session: [1] Name-City@Server01
> 2015-04-15 09:28:55.769 Script: pwd
< 2015-04-15 09:28:55.769 Script: /
> 2015-04-15 09:28:56.034 Script: get -nopermissions -nopreservetime -transfer="binary" -resumesupport="off" -- "sftp://Name-City/pnmpyt.txt@Server01" "C:\Windows\Temp\pnmpyt.txt"
. 2015-04-15 09:28:56.034 Listing file "sftp://File-City/pnmpyt.txt@Server01".
> 2015-04-15 09:28:56.034 Type: SSH_FXP_LSTAT, Size: 52, Number: 263
< 2015-04-15 09:28:56.034 Type: SSH_FXP_STATUS, Size: 50, Number: 263
< 2015-04-15 09:28:56.034 Status code: 4, Message: 263, Server: The requested operation failed., Language: en
< 2015-04-15 09:28:56.034 Script: Can't get attributes of file 'sftp://File-City/pnmpyt.txt@Server01'.
< 2015-04-15 09:28:56.050 Script: General failure (server should provide error description).
< 2015-04-15 09:28:56.050 Error code: 4
< 2015-04-15 09:28:56.050 Error message from server (en): The requested operation failed.
. 2015-04-15 09:28:56.050 Script: Failed

I've done a lot of searching of the error message over the past three days and can't seem to find an answer that applies in my case.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
The remotePath argument of Session.GetFiles is a path not URL, i.e. possibly /pnmpyt.txt, but definitely not sftp://Name-City/pnmpyt.txt.
_________________
Martin Prikryl
TonyL

Guest


Thanks a ton! With that correction, it worked like a charm.
TonyL

Guest


I've just completed getting all the code in place to successfully work with WinSCP in my .NET web application for downloading files from SFTP location. It runs just fine on my own machine, but when I publish it to my test server (Windows Server 2012 R2), it fails. My best guess is that where I am using C:\Windows\Temp for holding downloaded files, it does not have permission on the server. I have verified that the application itself has permission to that folder, but apparently WinSCP.exe does not. What identity does WinSCP.exe use (assuming it is different than the web application)? I have not been able to generate a log file on the server. Is there something else that I might be missing here?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Please attach a full log file showing the problem (using the latest version of WinSCP).

To generate log file, use /log=path_to_log_file command-line argument. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Btw, you can see the process identity in the log file.
_________________
Martin Prikryl
TonyL

Guest


AS I mentioned in my post, I have not been able to generate that log file. I've attempted to specifically point it to C:\Windows\Temp on the server, as well as my own pc's temp folder, to no avail.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Can you show us an example of the command-line with logging enabled?
TonyL

Guest


prikryl wrote:
Can you show us an example of the command-line with logging enabled?


Can you please tell me how to do that?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
You wrote before:
Quote:
AS I mentioned in my post, I have not been able to generate that log file. I've attempted to specifically point it to C:\Windows\Temp on the server, as well as my own pc's temp folder, to no avail.

So asked you to show us the command-line you have tried.
TonyL

Guest


prikryl wrote:
You wrote before:
Quote:
AS I mentioned in my post, I have not been able to generate that log file. I've attempted to specifically point it to C:\Windows\Temp on the server, as well as my own pc's temp folder, to no avail.

So asked you to show us the command-line you have tried.


I didn't actually use a command line to generate the file. Within Visual Studio, I used this: objSession.SessionLogPath = "WinSCPLog.txt"

This generated a file successfully to the Bin folder of the Web application. However, when it goes to the test server, it is not working.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
TonyL wrote:
I didn't actually use a command line to generate the file. Within Visual Studio, I used this: objSession.SessionLogPath = "WinSCPLog.txt"

This generated a file successfully to the Bin folder of the Web application. However, when it goes to the test server, it is not working.

I assume the application does not have a write access to the deployment folder. Use a full path in objSession.SessionLogPath and point it to a folder the process has a write access to.
Guest




I actually attempted that previously. My web application does have access to the deployment folder as well as to C:\Windows\Temp, and I've been able to verify that. But I'm unable to generate a log file to either location. It makes me suspect that the WinSCP takes on a different identity when it is running within the application? All that I capture is that error message:

Timeout waiting for WinSCP to respond - WinSCP has not responded in time (response log file
C:\Windows\TEMP\wscp1A48.00E447CC.tmp was not created). This could indicate lack of write permissions to the log folder or
problems starting WinSCP itself.

I notice just now that even when I attempt to point the log file to the deployment folder's bin directory, I still get that same notice, as though somehow it is defaulting to that C:\Windows\Temp even when I do not explicitly point it there.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
What kind of web application that is? I've just tested WinSCP .NET assembly with a fresh Azure web site and had absolutely no problems. Did you use NuGet package to make sure you have all set correctly?
TonyL

Guest


This is a Visual Studio 2013 web application that is hosted on a corporate Windows Server 2012 R2 on our local intranet. I did use the NuGet package when I set it up on the application.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
I used Visual Studio 2013 too. So it is probably something with the Windows Server setup.
TonyL

Guest


prikryl wrote:
I used Visual Studio 2013 too. So it is probably something with the Windows Server setup.


Can you tell me what security/permissions you have set up on the file directory on the Server as well as the C:\Windows\Temp file? Maybe that will unlock my problem for me by comparing those.

Thanks for all of your help!
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
It works for me with the defaults. It works even in a restricted Azure website environment (you cannot even control permissions there).
_________________
Martin Prikryl
TonyL

Guest


I was never able to get this working on the deployment server. Apparently it had to do with my .NET application not being able to secure permission to run winscp, no matter how I tried. I attempted to call it directly from within .NET, then I built a script file and called a Shell command. Both methods worked on my local development pc, but neither worked when moving it to a production server. Running the script in the command window worked on the deployment server... but when running it from within the .NET application, it appeared to work... no errors, nothing posted to the event logs, but it failed. For a work-around, I eventually worked with our company's Wintel team and they were able to set up Bitwise to check the SFTP folder (internal to our company) every 30 minutes and sent any file received to another folder that I could access. I have another item, a SQL Server SSIS package, that is upgrading now to SFTP. I have been able to get that working on my development machine. It will be deployed on other servers, and at this point I am waiting on our server teams to install WinSCP on those machines in order to test it.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License