FTP script Microsoft-IIS/7.5 to Unix
Hello all, I've visited here for years, just never got around to posting.
I'm looking for a little help writing a script to run on my server (CentOS), and its something I've never done before. I've got these text files and full permission to grab them off a Microsoft-IIS/7.5 server. I'm trying to automate the process with cron jobs. So far I'm striking out trying to do this with php and I keep wondering if doesn't make sense to at least try a bash or something like it. Here is the php code that gives this error; Can't open data connection Googling that everyone seems to say add this; ftp_pasv($conn_id, true); Code:
<?php |
Hello,
Here is a super basic setup for a ftp transfer using Bash. Code:
#!/bin/bash |
Thanks joshp.
Sorry to the forum for putting the dreaded ms word in my question title. Found a super simpleton youtubehttp://www.youtube.com/watch?v=QGvvJO5UIs4 that directs me to use nano. So I'm on my way. I'm still interested in any comments about the wisdom of dealing with this issue, or whether it's good or bad form to use a bash script where you just can't get it working in php. Seems to me there's an argument that server to server, I'm just getting closer to the heart of the matter. Here goes; #!/bin/bash HOST=ftp.server.com #This is the FTP servers host or IP address. USER=ftpuser #This is the FTP user that has access to the server. PASS=password #This is the password for the FTP user. # Call 1. Uses the ftp command with the -inv switches. -i turns off interactive prompting. -n Restrains FTP from attempting the auto-login feature. -v enables verbose and progress. ftp -inv $HOST << EOF # Call 2. Here the login credentials are supplied by calling the variables. user $USER $PASS # Call 3. Here you will change to the directory where you want to put or get cd /path/to/file # Call4. Here you will tell FTP to put or get the file. put test.txt # or get test.txt bye EOF I'm assuming call 3 is for changing directory on the remote server |
Have a good read of this http://linux.die.net/man/1/ftp
|
Thanks Chris.
This sure is a tough nut to crack! Code:
!/bin/bash <<<<<<< Got It >>>>>>>>>>> this line above should be ftp -invd $HOST 21 << EOF #Got lucky adding the known port Thanks to all |
Code:
MYPORT=21 You should quote variables. :) See http://mywiki.wooledge.org/Quotes and http://www.google.com/cse/home?cx=01...1bdfg5ga&hl=en will search about 15 linux-specific sites that deal with scripting and/or shell coding. Good Luck and let us know! |
Thanks for the links!
Working on two issues; I'm not finding the correct method to list different file names where a wildcard isn't going to work. FILES='namename_snamec.txt', 'snamead.txt', 'skudescadd.txt', 'OTHER123.TXT' mget $FILES Second issue is closing the ftp session on the remote server. It doesn't seem to understand; bye or EOF Trying; disconnect close exit 500 'ňABOR': command not understood |
Might be easier to use one of these tools
http://linux.die.net/man/1/ncftp http://linux.die.net/man/1/lftp http://www.ibm.com/developerworks/ai...lex/index.html http://russbrooks.com/2010/11/19/lftp-cheetsheet |
i would not use the old, deprecated and insecure ftp protocol.
i would turn on ssh (which comes with scp (for automated file transfers) and sftp (for an ftp like interactive prompt (read: babysitting <@:))). i would also install sshfs for extra ease-of-use of drag-and-drop local file copy emulation. i would disable root login and create public keys for each of my clients. |
Quote:
But the thing is I have no way to influence the msII server, that belongs to a huge company and I'm just one of many thousands of their customers. They determine the active connection and plain old FTP on port 21. I'm pretty sure I was mistaken about closing the ftp session now. It's all about my server not finding a proper address or blocking the ftp port address, something along that line. |
I should first thank you all for the help and let you know that the problem came down to white listing the remote server. Why didn't I think of that? We're fortunate to have the hosting support we have.
Now perhaps it's time to end this thread. I've got 11 crons and all tested good the first time through. That covers a bunch of automation for all the text. But I have something of an interesting dilemma with the images. I need to FTP and rename multiple images, from weekly updates, and I'm trying to come up with a script for this. The interesting part is the folder names change every week, so at this early point in the year the WebImages folder on the remote server has Week1 - Week5. It wouldn't be so bad to use a wildcard like Week* if it's only five folders with maybe 200 images each, but what about later in the year when there might be Week1 - Week48 (200 * 48 = 9600 images) and only 200 images are actually new at the time? A suggestion I got elsewhere was to look into using brace expansion running a cron job and/or a separate script to clear old folders and specify a brace number range. Any thoughts or links or suggestions are greatly appreciated. Especially any that may direct me to where this type of question, (sort of a tricky bash requirement), might find the best response on this website. Thanks again to all. ~Motorcity |
You need to know the definition/calculation of the week number at the remote end, then use the date cmd to give you the current week num
http://linux.die.net/man/1/date Code:
%U Target week num is then Code:
weekdir=Week${weeknum} http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ However(!), now you've solved the underlying issue (whitelisting) you may want to revert to php. Imho, if this is a standalone cron job, stick with bash; if its called from Apache, go php. |
Totally awesome links there Chris!
Thank you very much! Quote:
On the other hand, this script with renaming the files & changing folder numbers is more complex than the simple bash files I'm currently testing. This project of automating what I've been doing very manually has been long overdue. I'm looking for the easiest path to running on autopilot here. So once again I thank you for the consideration, and appreciate hearing your opinion. ~Motorcity |
If its time based, use cron, if event based (based on something happening in the website), use Apache to call php.
I believe there is a pure cli (non-apache) way to use php, but I've rarely seen it used (& I'm not a php guy anyway...) |
All times are GMT -5. The time now is 01:54 AM. |