1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: NcFTP Running a Script

Discussion in 'Web Design & Development' started by nickelodeon, Apr 6, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. nickelodeon

    nickelodeon Thread Starter

    Joined:
    Nov 29, 2002
    Messages:
    590
    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
     
  2. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
  3. nickelodeon

    nickelodeon Thread Starter

    Joined:
    Nov 29, 2002
    Messages:
    590
    Sure did.

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

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
    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...
     
  5. nickelodeon

    nickelodeon Thread Starter

    Joined:
    Nov 29, 2002
    Messages:
    590
    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?
     
  6. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
    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...
     
  7. nickelodeon

    nickelodeon Thread Starter

    Joined:
    Nov 29, 2002
    Messages:
    590
    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!
     
  8. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
    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...
     
  9. nickelodeon

    nickelodeon Thread Starter

    Joined:
    Nov 29, 2002
    Messages:
    590
    hmm I ran that but came up with an error: I can only retrieve regular files. Any thoughts?
     
  10. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
    Hmmm, based on the NcFTPGet docs, it appears the "-R" option would be needed:

    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...
     
  11. nickelodeon

    nickelodeon Thread Starter

    Joined:
    Nov 29, 2002
    Messages:
    590
    You sir are a genius. Works perfect. Just added the *.* to the end of it thank you very much!
     
  12. tomdkat

    tomdkat Retired Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,148
    Naw, not a genius at all. :)

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

    Peace...
     
  13. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/915228

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice