scripting syntax to connect to FTP

Advertisement

Sector7G
Donor
Joined:
Posts:
6
Location:
United States

scripting syntax to connect to FTP

I'm a newbie at WinSCP. I have been reading the help files and Google, but I'm missing something. I think I have the syntax wrong in my batch file. When I follow the prompts in the command window to enter the FTP server, user name, and password, it works. But when I put it all into a batch file, I get an error:
access denied
authentication failed

This is what I have in my batch file (with a different user/pw, of course). While reading over the command line instructions, I did not see an example that had a user id and password for FTP. There are examples for FTPS and SFTP. Is there a different syntax for FTP?
option batch abort
option confirm off
open ftp://username:password@ftpserver.com

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,440
Location:
Prague, Czechia

Re: scripting syntax to connect to FTP

Your syntax is correct.
Are there any special characters in your username or password?

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.

Reply with quote

Sector7G
Donor
Joined:
Posts:
6
Location:
United States

Thank you for your reply. I was able to generate the log file, and I have attached a copy for you. The end of the log says "530 Login or Password incorrect". But this is the same user/password that I enter when I run the commands manually. It works there, just not in the batch file.
  • winscp.log (3.11 KB, Private file)

Reply with quote

Guest

Sector7G wrote:

Thank you for your reply. I was able to generate the log file, and I have attached a copy for you. The end of the log says "530 Login or Password incorrect". But this is the same user/password that I enter when I run the commands manually. It works there, just not in the batch file.

I forgot to mention, there are no special characters in the user name or password.

Reply with quote

martin
Site Admin
martin avatar

Try to add /loglevel=* to command-line. It makes the log record the actual password. Check that the password is correct.

Reply with quote

Advertisement

Sector7G
Donor
Joined:
Posts:
6
Location:
United States

martin wrote:

Try to add /loglevel=* to command-line. It makes the log record the actual password. Check that the password is correct.

I added the log level, then tried running my batch file again. It still failed saying "login or password incorrect". I looked at the log file (several times). I am sure that the user/pw are correct. If I open a command line, and enter the values one line at a time (open site, enter user name, enter pw) then it works. There are no special characters in the user/pw. I have attached the most recent log file. I did replace the user/pw with stars in the log.

thank you
  • log.txt (3.15 KB, Private file)

Reply with quote

Sector7G
Donor
Joined:
Posts:
6
Location:
United States

martin wrote:

Can you attach a log of a successful interactive session?
Do you mean a log from a manual session? (where I enter parameters one at a time instead of using a script). I created a log from a successful manual session.
thank you
  • log04022015.log (30.15 KB, Private file)

Reply with quote

martin
Site Admin
martin avatar

I mean from a log, where you "follow the prompts in the command window to enter the FTP server, user name, and password, it works."

The log you have attached shows a failed session.

Reply with quote

Advertisement

Sector7G
Donor
Joined:
Posts:
6
Location:
United States

My apologies... I must have pulled the wrong file. The file I attached is from a successful session today.
  • log04062015.log (29.93 KB, Private file)

Reply with quote

martin
Site Admin
martin avatar

You are using an SFTP protocol in the interactive session (you do not specify a protocol in an open command and WinSCP defaults to SFTP). While you use an FTP protocol in the failed session (you specify ftp:// explicitly).

Reply with quote

Sector7G
Donor
Joined:
Posts:
6
Location:
United States

martin wrote:

You are using an SFTP protocol in the interactive session (you do not specify a protocol in an open command and WinSCP defaults to SFTP). While you use an FTP protocol in the failed session (you specify ftp:// explicitly).

I have tried both FTP and SFTP in the batch file. When I use SFTP and run the script, the window returns the error: The server rejected SFTP connection, but it listens for FTP connections. Did you want to use FTP protocol instead of FTP? Prefer using encryption.

Thank you for your comments. I hope I can get this working.
  • log_OHG_04142015.log (4.66 KB, Private file)
Description: Contains both the batch file & log text.

Reply with quote

martin
Site Admin
martin avatar

In the GUI you connect to ftp.ohiohealthgroup.com, what resolves to 192.168.30.242, while in the latest log you connect to ohiohealthgroup.com, what resolves to 64.87.23.209.

Reply with quote

Advertisement

Guest

martin wrote:

In the GUI you connect to ftp.ohiohealthgroup.com, what resolves to 192.168.30.242, while in the latest log you connect to ohiohealthgroup.com, what resolves to 64.87.23.209.

It's working! Thank you for your help. For anyone else reading this, here is a summary. I tried both of these connection strings in a batch file, and they failed:

open sftp://*******:********@ohiohealthgroup.com
open ftp://*******:********@ohiohealthgroup.com

The correct connection string is:
open sftp://*******:********@ftp.ohiohealthgroup.com

So the connection string contains both sftp & ftp.

Reply with quote

martin
Site Admin
martin avatar

So the connection string contains both sftp & ftp.
It does not really. The ftp.ohiohealthgroup.com is just a hostname, it does not specify a protocol.

Reply with quote

rixter77
Joined:
Posts:
2
Location:
Boulder, CO

scripting syntax to connect to FTP when password fails

The previous thread about "scripting syntax to connect to FTP" almost answered my question. I was glad to learn the tip about putting /loglevel=* to see if there is a password failure.

That is what is happening in my case; here is the log file:
2015-04-20 19:28:38.745 Connected with tourism-engine.com. Waiting for welcome message...
< 2015-04-20 19:28:38.776 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
< 2015-04-20 19:28:38.776 220-You are user number 1 of 50 allowed.
< 2015-04-20 19:28:38.776 220-Local time is now 01:28. Server port: 21.
< 2015-04-20 19:28:38.776 220-IPv6 connections are also welcome on this server.
< 2015-04-20 19:28:38.776 220 You will be disconnected after 15 minutes of inactivity.
> 2015-04-20 19:28:38.776 USER automat@tourism-engine.com
< 2015-04-20 19:28:38.806 331 User automat@tourism-engine.com OK. Password required
> 2015-04-20 19:28:38.807 PASS bC3-fpK
< 2015-04-20 19:28:42.175 530 Login authentication failed

However, the above log does *not* show the complete password. I am not going to reveal the complete password here, of course, but the next character in the password is a semi-colon, or ; character.
This password works in the WinSCP GUI login; but the fact that the log stops on that character makes me suspect the problem is the semi-colon in the password, and how it is getting fed to login.
I do not see any documentation saying this character should not be used in a password.
Can anyone help me verify if this is the case?

thanks,
rixter

Reply with quote

rixter77
Joined:
Posts:
2
Location:
Boulder, CO

Re: scripting syntax to connect to FTP when password fails

I found the problem: it was the ; in the password. Eliminating that allowed the password to work....

rixter77 wrote:

The previous thread about "scripting syntax to connect to FTP" almost answered my question. I was glad to learn the tip about putting /loglevel=* to see if there is a password failure.

That is what is happening in my case; here is the log file:
2015-04-20 19:28:38.745 Connected with tourism-engine.com. Waiting for welcome message...
< 2015-04-20 19:28:38.776 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
< 2015-04-20 19:28:38.776 220-You are user number 1 of 50 allowed.
< 2015-04-20 19:28:38.776 220-Local time is now 01:28. Server port: 21.
< 2015-04-20 19:28:38.776 220-IPv6 connections are also welcome on this server.
< 2015-04-20 19:28:38.776 220 You will be disconnected after 15 minutes of inactivity.
> 2015-04-20 19:28:38.776 USER automat@tourism-engine.com
< 2015-04-20 19:28:38.806 331 User automat@tourism-engine.com OK. Password required
> 2015-04-20 19:28:38.807 PASS bC3-fpK
< 2015-04-20 19:28:42.175 530 Login authentication failed

However, the above log does *not* show the complete password. I am not going to reveal the complete password here, of course, but the next character in the password is a semi-colon, or ; character.
This password works in the WinSCP GUI login; but the fact that the log stops on that character makes me suspect the problem is the semi-colon in the password, and how it is getting fed to login.
I do not see any documentation saying this character should not be used in a password.
Can anyone help me verify if this is the case?

thanks,
rixter

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum