# WinSCP scripting help needed

I have a working winscp for a different vendor using sftp and getting a file.. For this new script the ftp address is a little different, I am sending (or putting the file) to an ftp.. Something is wrong, but the error message and anything that trys to explain the error message is very vage..  I was hoping someone here could look at the code and see what my error is..

Also I can connect to the ftp3 site through the gui program.. It would be great if from there it would offer a button to create the script from the working connection.. But I don't see it nor did I find anything on the web that suggests the option.. IF there is one, and you know about it, that would help too..

Anyway, below is the information (some data changed to protect) that I hope is enough for someone to point me in the right direction of my blunder..

I have corrected something, although definately not right.. I had made a change, and did not realize it was so bad it stopped creating the log file. I had added on the "AINET\aaaaFTP1"   This has to go somewhere, but obviously not where I placed it..

Connection info: (changed to protect)
Host name: ftp3.something.net
Server type: FTP (Remote port 21)
UserID: ftp3.something.net|AINET\aaaaFTP1

Script
option batch on
option confirm off
open ftp://myusername:psswd@ftp3.something.net:21    (log built with this code)
#move to correct directory
cd /LEDT/compressed
option transfer binary
#Send file to ftp site
put c:\foldername\LEDT_MAN.zip
close
exit

Error from log
. 2014-04-03 12:51:58.535 Connecting to ftp3.something.net ...
. 2014-04-03 12:51:58.551 The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for.
. 2014-04-03 12:51:58.551 Connection failed.
LVL 1
###### Who is Participating?

Commented:
reread the doc on a better screen

something like this should do

option batch abort
option confirm off
...

with or without ftp://

you should debug by typing commands manually : it will make things much easier
0

Commented:
the error is unrelated with your script : it is a windows error (actually winsock) that indicates that name resolution cannot be performed.

maybe the host is setup as ipv6 only and winscp asks for ipv4 ? try to nslookup the host name and see if you have an A record. do the lookup on your ISA if you have one

alternatively your user:password@site syntax may not be supported. if you have not confirmed the syntax works, try removing it just to make sure
0

Author Commented:
Thanks skullnobrains --  I can see you understand ftp.. But, since I am someone who cringes when forced to do it, you have lost me with some of your suggestions..

Why would there be a windows error (or winsock)  when running it in script but not in the same programs window based program..??

But perhaps.. After all I run it on my computer when I run it in the windows program.. I am not sure how else to test the script outside of the program I must write the script for, which is SSIS.. And the SSIS is run on a server so not my own computer..

How do I test what the host is ipv6, ipv4 or something else??? What is nslookup?? How do I do that?

The user:password@site synatx is copied from someother script that runs a WinSCP script for another site.. Problem is theirs is a secure ftp.. This one seems odd from a normal ftp due to the "|AINET\aaaaFTP1" piece and very true.. I not sure how to attach that.. I tried exactly as stated  "ftp3.something.net|AINET\aaaaFTP1" as the window version of WinSCP took it this way and worked.. But then I found the error log in the script version stopped being created, so I figured it was seriously incorrect.. So I have tried adding the "AINET\aaaaFTP1" to the front of the change directory path.. That gave me back my error log, but still failed with same error..

But removing any trying to get into the FTP site??  I don't see what I will get from that, except I will not get into the ftp site..
0

Commented:
Why would there be a windows error (or winsock)  when running it in script but not in the same programs window based program..??

programs that run on the windows platform use windows sockets to communicate with the network regardless of the language they are written on or the fact that they are builtin windows. same applies to any OS.

How do I test what the host is ipv6, ipv4 or something else??? What is nslookup?? How do I do that?

open a command line and type "nslookup ftp3.something.net" (with the actual hostname)

read below, you might not need that

---

AINET\aaaaFTP1

i guess i missed that part previously. no idea what this mess is.

if it is actually part of your user id, it should be placed in the url between ftp:// and the first following :

difficult to figure out : i assume ftp3... is ,not your actual userid

the syntax is

so if it is part of the user id, it probably should go

where the hell does this AINET stuff come from ?
0

Author Commented:
where the hell does this AINET stuff come from ?

Your guess is as good as mine..  Our company did not create the ftp area the other company did, we are just given instructions on how to use it. When I get it to work in the windows program, I put all of it into the Hostname including the "|AINET\aaaftp1" and it works just fine..

The aaa is something different, but I changed it a little not knowing what it is I didn't know if any of it was a security breach, but the "|AINET\" and "ftp1" are as I was given which I left thinking that might be specific to whatever it is..  and changing it too much would cause anyone trying to help question what it is..  The aaa part though looked like something vendor specific so I changed it..

I have removed it, moved it down into being part of the change directory string "cd AINET/aaaftp1/LEDT/compressed" as well as stuck it in to the Hostname exactly as the vendor has asked me to..  When I stuck it into the Hostname exactly the script broke so much that I no longer was getting the error log.. It took me a little while to realize that the error log I kept looking at to see if changes I made was effecting the output had an old timestamp on it, and when I deleted it and ran it, no error log was created.. When I removed it or moved to the "change directory logic area"  I got the error log back again..

open a command line and type "nslookup ftp3.something.net" (with the actual hostname)

I will try it on the computer I  run the script from, let me know if I have to ask the vendor to run it on the computer the ftp3 is setup on instead..
0

Author Commented:
Ok in the command line.. When I typed in the following

nslookup ftp3.something.net

I got back:
Server: uldc01.ourcompanyname.local

home: ftp3.something.net

But when I entered

nslookup ftp3.something.net|AINET\aaaftp1

I got back:
The system cannot find the path specified.

I am pretty sure the AINET\aaaftp1 thing is trying to drop me into a specific area on their ftp site, but moving to it after logging in with the change Directory prompt is too late to pass muster with their security checks.. But this syntex though fine for the window program, needs to be different in the script..  Well that is my guess anyway..
0

Author Commented:
I got further.. !!!   Actually I fixed a typo in the hostname that I found.. So I have a different error now.   This setup is with the "|AINET\aaaftp1" in the change directory part of the logic and not attached to the username..

. 2014-04-08 10:04:10.749 Connecting to ftp3.something.net ...
. 2014-04-08 10:04:10.858 Connected with ftp3.something.net. Waiting for welcome message...
< 2014-04-08 10:04:10.921 220-Microsoft FTP Service
< 2014-04-08 10:04:10.921     Property of Something - Authorized Users Only
< 2014-04-08 10:04:10.921     Only individuals currently with accounts on this
< 2014-04-08 10:04:10.921     computer authorized by something may access
< 2014-04-08 10:04:10.921     the data and resources on this computer and it's
< 2014-04-08 10:04:10.921     network.
< 2014-04-08 10:04:10.936     All information stored on this computer and it's
< 2014-04-08 10:04:10.936     network is the property of something and is
< 2014-04-08 10:04:10.936     subject to all the protections accorded intellectual
< 2014-04-08 10:04:10.936 220 property.
> 2014-04-08 10:04:10.936 USER ourcompany
< 2014-04-08 10:04:10.999 331 Valid hostname is expected.
> 2014-04-08 10:04:10.999 PASS *******
< 2014-04-08 10:04:11.108 503 Login with USER first.
. 2014-04-08 10:04:11.108 Connection failed.
0

Commented:
if it is a path, it should be \AINET or /AINET and not |AINET

i'd make a wild assumption that | means a relative path instead of an absolute path in wscp so you should actually cd to AINET or ./AINET instead of |AINET
apparently, this corresponds to what you tried more or less

the simplest thing to do to debug is to run a regular ftp from the command line or from a browser or even winscp without the AINET stuff and look at the folder contents

looking at winscp documentation, AINET corresponds to a workspace, which would be a saved session, probably with a local directory and possibly saved passwords and the likes. it should work without any of this mess.

btw, as far as i understood from the somehow obscure documentation, you should remove ftp:// from the open command. it seams reasonable to thing that winscp lokked for ftp://... as a hostname which would be consistent with the error
0

Commented:
oups cross posted. apparently you connected and were kicked because the server expected a logon in the form user@host

the error on password is just a consequence

it would be easier if you posted the updated script
0

Author Commented:
We are coming down to the Host name is correct without the "|AINet\aaaftp" on it.. But somewhere I need to declare the username..

My manager did it through a linex prompt, and had a spot for username..  Looking at the WinSCP Login..
The host name is : ftp3.something.net
The user name is : ftp3.something.net|AINet\aaaftp

How do I put in the username to the script??
0

Author Commented:
I was thinking that.. I will try your syntax to see if I possibly had a colon or slash out of place somewhere..  But, my intial trial when I had the Ahhh. moment was not so good.. It errored out and again did not give me an error log.. Something about putting that pipe -or- the backslash in that line wether it be the username or the hostname has it choking..

I would love this to work.. But I have created a dos Batch command file that seems to be working without using winscp at all.. I just would hate to have to use this and have a different way I run ftp launches that I when I have to revisit 2 years from now will have me questioning what I did and why I did it..  Also I am not quite sure on how to launch the Batch file from the SQL SSIS task (which is why I am building this script ftp in the first place.)
0

Author Commented:
Whoooo  Hooooo   SUCESS !!!!    I think when I tried it again with your suggestion I put the ftp:// on it which I had not done in the previous test of it..

Thank you for all you hand holding..
0

Author Commented:
Again... Thank you for your kindness and patience..  If I could give you an A++++  I would.
0

Commented:
thanks. good to see you got it right at some point even though part of what i contributed was probably misleading.

feel free to post the working script. i believe you're not the only one struggling with winscp

---

note that tools such as wput or curl have been ported to windows and allow to do such things in much simpler ways on a single command line such as
toolname X:\path\to\source_file ftp://user:pass@server/path/to/dest
0

Author Commented:
OK.. This is my working final code

FTP Information given:

Host name:        ftp3.something.net
Server type:      FTP (Remote port 21)
UserID:               ftp3.something.net|AINET\aaaFTP1

--------------------------------------------------------------

option batch on
option confirm off
#
#Connect Syntax  is  ftp://UserID:password@HostName:port (port is optional)
#
open ftp://ftp3.something.net|AINET\aaaFTP1:psswd@ftp3.something.net:21
#
#move to correct directory
#
cd /foldername1/Foldername2
option transfer binary
#
#Send file to ftp site
#
put C:\folder1\folder2\ZipFiles\zipfilename.zip
close
exit
0

Commented:
pretty straightforward using the regular url syntax. thanks for sharing.
0

IT ConsultantCommented:
HI. Need help with something similar to what moosetracker was doing and skullnobrains was helping with...

Trying to automate an sftp file transfer. One file, nightly uploaded.  I've got some of my script to do this drafted.  I've tested my connection via GUI WinSCP.
1. how do I test my commands (line by line) that I have in my script?   This would allow me to debug as I go.
2. once I have a script that works, how do I automate it?  (I'd like to schedule it via Windows scheduler.) I think I'd create a new task scheduled item.. that the action is 'start a program', and then I call "C:\Program Files ...\WinSCP\WinSCP.exe" to launch winscp.  (Or maybe I use WinSCP.com?)   This only launches the program, how do I get my script, which has all my parameter and settings inside) to execute.  Do I add that, let's say it's upload.bat to my schedule task?  Put that in the arguments box?
0

Commented:
- you are reopening a VERY old thread which is not really the way things work

- the question you are asking is quite different, and includes subquestions

- you obviously did not read the basic winscp short docs

---

1) just run your script in a terminal : the error messages are explicit and mention which commands fail. alternatively, you can type the commands one by one in your terminal.

2) yes, scheduled task is the way.

---

winscp.exe should allow you to give the script name as an argument.

here is how to confirm and learn how to run a script :
- google for "winscp command line"
- scroll down to console/scripting mode
- find this : winscp.com /script="C:\Users\martin\Documents\myscript.txt"

good scripting
0

IT ConsultantCommented:
Hello - Thanks for your reply. No offense meant to anyone on the comment to old post.  I actually did read the basic docs. I've reviewed them, and did try to 'implement'.  I was able to run all lines of my script in terminal, and all commands execute successfully, without error.  Great.   Getting the script name to run as an argument is where I'm getting stuck.  I literally think the issue is getting the scheduled task part set up in Widows 2008 R2 server, not the script.

I will follow your links - again - and delve into this further.  If more questions still exist,  I will create a NEW POST.
0

Commented:
Getting the script name to run as an argument is where I'm getting stuck

see above :

winscp.com /script="C:\Users\martin\Documents\myscript.txt"


---

if the above works in your terminal but not from the task scheduler,

- use the complete path to winscp.com which might not be in the PATH available from the scheduler's context (PATH is the list of folders where the system will look for commands)
- if it still does not work, redirect the output to a log file ( ... > c:\log.txt ) most likely the problem is due to access rights. obviously make sure you test on the command line with the same user you use for scheduling.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.