Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: SFTP script not completing

OK, I see.

I assume that what you call "script" is actually a Windows batch file.

The first command in the batch file runs WinSCP in GUI mode. And stops there.

You have to move your WinSCP commands to script file and tell WinSCP to execute that script file in scripting mode:

"C:\Program Files (x86)\WinSCP\WinSCP.com" /script=c:\path\to\winscp.txt

And add open sftp://username:Password@uploads.podium.co command to the beginning of the winscp.txt.
Guest

Re: SFTP script not completing

martin wrote:

What is localchdir? Where have you seen that?

It should be lcd "C:\Needles\Podium"
https://winscp.net/eng/docs/scriptcommand_lcd


I tried that an it still does not work. WinSCP opens and then it shows 2 directories. The left is C:\ and the right is the correct FTP directory. What is causing the left directory to not chagne to C:\Needles\Podium?

Here is the script.
# Connect to SFTP
"C:\Program Files (x86)\WinSCP\WinSCP.exe" sftp://username:Password@uploads.podium.co
# Change local directory
lcd "C:\Needles\Podium\"
#Upload files to Podium
put NeedlesPodiumExportWithRelease.csv NeedlesPodiumExport.csv
pause
#Disconnect
close
#Exit WinSCP
exit
tgra

SFTP script not completing

Hello All -

I am running into problems fully executing the script below. I run the script it opens winscp and logs in fine. I see the remote directory. I am trying to change the local directory to C:\Needles\Podium but it will not change and the local dir stays at C:\. What do I need to do to have the script change the local dir to C:\Needles\Podium and upload any files that end in csv? I have tried using lcd C:\Needles\Podium and that does not work either. Below is the ending of the logfile and .ps script.

LogFile
. 2018-11-29 11:51:54.312 Server offered these authentication methods: publickey,password
. 2018-11-29 11:51:54.312 Prompt (password, "SSH password", <no instructions>, "&Password: ")
. 2018-11-29 11:51:54.312 Using stored password.
. 2018-11-29 11:51:54.328 Sent password
. 2018-11-29 11:51:54.437 Access granted
. 2018-11-29 11:51:54.437 Opening session as main channel
. 2018-11-29 11:51:54.968 Opened main channel
. 2018-11-29 11:51:55.156 Started a shell/command
. 2018-11-29 11:51:55.203 --------------------------------------------------------------------------
. 2018-11-29 11:51:55.203 Using SFTP protocol.
. 2018-11-29 11:51:55.203 Doing startup conversation with host.
> 2018-11-29 11:51:55.218 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2018-11-29 11:51:55.296 Type: SSH_FXP_VERSION, Size: 150, Number: -1
. 2018-11-29 11:51:55.296 SFTP version 3 negotiated.
. 2018-11-29 11:51:55.296 Unknown server extension posix-rename@openssh.com="1"
. 2018-11-29 11:51:55.296 Supports statvfs@openssh.com extension version "2"
. 2018-11-29 11:51:55.312 Unknown server extension fstatvfs@openssh.com="2"
. 2018-11-29 11:51:55.312 Supports hardlink@openssh.com extension version "1"
. 2018-11-29 11:51:55.312 Unknown server extension fsync@openssh.com="1"
. 2018-11-29 11:51:55.312 We believe the server has signed timestamps bug
. 2018-11-29 11:51:55.312 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
. 2018-11-29 11:51:55.312 Limiting packet size to OpenSSH sftp-server limit of 262148 bytes
. 2018-11-29 11:51:55.312 Getting current directory name.
. 2018-11-29 11:51:55.312 Getting real path for '.'
> 2018-11-29 11:51:55.312 Type: SSH_FXP_REALPATH, Size: 10, Number: 16
< 2018-11-29 11:51:55.390 Type: SSH_FXP_NAME, Size: 39, Number: 16
. 2018-11-29 11:51:55.390 Real path is '/uploader'
. 2018-11-29 11:51:55.453 Listing directory "/uploader".
> 2018-11-29 11:51:55.453 Type: SSH_FXP_OPENDIR, Size: 18, Number: 267
< 2018-11-29 11:51:55.531 Type: SSH_FXP_HANDLE, Size: 13, Number: 267
> 2018-11-29 11:51:55.531 Type: SSH_FXP_READDIR, Size: 13, Number: 524
< 2018-11-29 11:51:55.624 Type: SSH_FXP_NAME, Size: 207, Number: 524
> 2018-11-29 11:51:55.624 Type: SSH_FXP_READDIR, Size: 13, Number: 780
< 2018-11-29 11:51:55.718 Type: SSH_FXP_STATUS, Size: 28, Number: 780
< 2018-11-29 11:51:55.718 Status code: 1
> 2018-11-29 11:51:55.718 Type: SSH_FXP_CLOSE, Size: 13, Number: 1028
. 2018-11-29 11:51:55.718 ..;d;0;2018-10-25T19:02:04.000Z;3;"0" [0];"516" [516];rwxr-xr-x;0
. 2018-11-29 11:51:55.781 Startup conversation with host finished.

Script

# Connect to SFTP ADDED two extra ^^ to allow the entry of the special character in the password
"C:\Program Files (x86)\WinSCP\WinSCP.exe" /log=logfile.log sftp://USER:PASSWORDe@FTPSERVER
# Change local directory to file location
localchdir ("C:\Needles\Podium")
# Upload files to Podium
put C:\Needles\Podium\NeedlesPodiumExport.csv
# Disconnect
close
# Exit WinSCP
exit