# Solved: NcFTP Running a Script



## nickelodeon

Hey,

I have a script in a text file I would like NcFTP to run but not sure how to do it? In ftp.exe its something like -s:filename.txt but there isn't such command that I know of in NcFTP.

Thanks


----------



## tomdkat

Have you read the NcFTP documentation? 

NcFTPPut
NcFTPGet

Peace...


----------



## nickelodeon

Sure did.

Doesn't say in there how to actually execute a script from a text file.


----------



## tomdkat

Based on the doc on the NcFTP site, it appears NcFTP is designed to be called from within a script vs it processing a response file, like other FTP clients.

So you would have a batch file on Windows or a shell script on *nix to call NcFTP to login to the FTP site and transfer whatever files you need to transfer in an unattended or "batch" manner.

If you're wanting to send files, use NcFTPPut and if you're wanting to download files, use NcFTPGet.

So, let's say you put the login information in a text file called "login.txt" like this:



Code:


host mysite.com
user myid
pass mypasswd

In your batch file or shell script, you would invoke NcFTP like this to send a file:

ncftpput -f login.txt /remote/destination/path/for/file {local file}

For example:

ncftpput -f login.txt www/images header-img.png

The above would login to the FTP site specified in login.txt and upload the file "header-img.png" in the current directory to the "www/images" directory on the FTP site.

Peace...


----------



## nickelodeon

Ah ok.

What I wanted to do was create a script that downloads specific files from the website to the local disk (like a backup). I have the script written out and if I execute it line by line it works so what I wanted was to run a command from NcFTP to read from the text file and execute those commands. 

So say I've named this file download.txt and it is saved C:/download.txt how would I create a batch file to execute this with NcFTP?


----------



## tomdkat

It would basically be a one line batch file:

ncftpget -u {userid} -p {password} ftp://{ftp.addr.ess} {\path\to\backup\directory} {/remote/file/} {/remote/file/}

Example:

ncftpget -u myid -p mypassword ftp://ftp.tomdkatrocks.com c:\backups\website /www/uploads /www/logs/this-log.txt

This should download ALL of the "uploads" directory and the "/www/logs/this-log.txt" file to the c:\backups\website directory.

If you wanted to store the login info separately, I would create a file like login.txt above and change the above command to:

ncftpget -f login.txt ftp://ftp.tomdkatrocks.com c:\backups\website /www/uploads /www/logs/this-log.txt

At least, this should get you started.

Peace...


----------



## nickelodeon

I've just been doing a bit of playing around and wrote a batch file with the following:

ncftp -u user-p password ftp.domain.com.au
ncftp lcd c:\myobback\success
ncftp cd /myobback/456/
ncftp mget *.*
ncftp lcd c:\myobback\789
ncftp cd /myobback/789/
ncftp mget *.*
ncftp lcd c:\myobback\111
ncftp cd /myobback/111/
ncftp bin
ncftp mget *.*
ncftp quit

When I open it it logs me in fine but then doesn't continue with the lcd command. Do you know why?

Thanks!


----------



## tomdkat

nickelodeon said:


> I've just been doing a bit of playing around and wrote a batch file with the following:
> 
> ncftp -u user-p password ftp.domain.com.au
> ncftp lcd c:\myobback\success
> ncftp cd /myobback/456/
> ncftp mget *.*
> ncftp lcd c:\myobback\789
> ncftp cd /myobback/789/
> ncftp mget *.*
> ncftp lcd c:\myobback\111
> ncftp cd /myobback/111/
> ncftp bin
> ncftp mget *.*
> ncftp quit
> 
> When I open it it logs me in fine but then doesn't continue with the lcd command. Do you know why?
> 
> Thanks!


Instead of that, try this:

ncftpget -u user -p password ftp.domain.com.au c:\myobback\success /myobback/456/
ncftpget -u user -p password ftp.domain.com.au c:\myobback\789 /myobback/789/
ncftpget -u user -p password ftp.domain.com.au c:\myobback\111 /myobback/111/

Based on the NcFTPGet doc, NcFTPGet will use binary transfers unless explicitly instructed to use ASCII transfers.

Based on the NcFTP doc, it appears the NcFTP program supports command line arguments to log you in to the remote server but that's it. The other commands need to be entered interactively. That's why the NcFTPPut, NcFTPGet, and other programs exist.

Peace...


----------



## nickelodeon

hmm I ran that but came up with an error: I can only retrieve regular files. Any thoughts?


----------



## tomdkat

nickelodeon said:


> hmm I ran that but came up with an error: I can only retrieve regular files. Any thoughts?


Hmmm, based on the NcFTPGet docs, it appears the "-R" option would be needed:



> You can retrieve an entire directory tree of files by using the -R flag. However, this will work only if the remote FTP server is a UNIX server, or emulates UNIX's list output. Example:
> 
> $ ncftpget -R ftp.ncftp.com /tmp /pub/ncftp
> 
> This would create a /tmp/ncftp hierarchy.


However, you probably don't want to remote directory structure recreated on your local system. So, maybe try appending an asterisk at the end of the current lines would do the trick?

Maybe try:

ncftpget -u user -p password ftp.domain.com.au c:\myobback\success /myobback/456/*.*
ncftpget -u user -p password ftp.domain.com.au c:\myobback\789 /myobback/789/*.*
ncftpget -u user -p password ftp.domain.com.au c:\myobback\111 /myobback/111/*.*

If not, try adding the "-R' option (per the docs and example in the docs) and see if that works. If that doesn't, contact them to find out what you'll need to do.

Peace...


----------



## nickelodeon

You sir are a genius. Works perfect. Just added the *.* to the end of it thank you very much!


----------



## tomdkat

Naw, not a genius at all. 

Glad things are working for you! Please mark this thread as "solved" if all is well. 

Peace...


----------

