FTP failed to copy mulitple files from multiple directory


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users FTP failed to copy mulitple files from multiple directory
# 1  
Old 11-08-2011
MySQL FTP failed to copy mulitple files from multiple directory

I am using below scripts to copy all the files from multiple folders. By executing individually command i am able to copy all the files but using scripts only getting first file. System is ignoring the second CD and mget command.
Code:
HOST=server.com
USER=loginid
PASSWD="abc"
echo "open $HOST
user $USER "${PASSWD}"
binary
prompt off" > /tmp/ftp.$$

echo "cd /home/mylogin/Test"  >> /tmp/ftp.$$
echo "mget *.* "  >> /tmp/ftp.$$
echo "cd \"/home/mylogin/Test2/Important Doc/\" " >> /tmp/ftp.$$
echo "mget *.*  "  >>  /tmp/ftp.$$
echo "bye" /tmp/ftp.$$
ftp -ivn < /tmp/ftp.$$

Similarly I want to add around 50 folders to copy all the files from windows folder to unix folder. Please advice.

Moderator's Comments:
Mod Comment Use code tags, see PM, thanks.

Last edited by zaxxon; 11-09-2011 at 05:36 AM.. Reason: code tags, see PM
meetvipin
# 2  
Old 11-08-2011
You don't have to reopen the same file 50 times to add 50 lines. You may not even need a file at all.

That 'bye' doesn't even end up in the file at all.

"*.*" is a DOS-ism, if you want all files in UNIX use *

Code:
ftp <<EOF
open $HOST
user $USER "${PASSWD}"
binary
prompt off
cd /home/mylogin/Test
mget *
cd "/home/mylogin/Test2/Important Doc/"
mget *
bye
EOF

# 3  
Old 11-09-2011
Still not working.

I tried another method - creating a file and passing to FTHub jobs.
Code:
/usr/bin/ftp -ivn < /tmp/ftp.24459

where /tmp/ftp/24459 is as below
Code:
open server.com
user loginid Passwrod 
binary
prompt off
cd /home/mylogin/Test
mget *
cd /home/mylogin/Test2/Important_Doc/
mget *
bye
.

Still files from first folder are being copied. I swaped the folder then same file are coping from first folder only.

Similarly i want o add 50 files -
Code:
cd /home/mylogin/Test
mget *
....
....
cd /home/mylogin/Test2/Important_Doc/
mget *

Smilie

Moderator's Comments:
Mod Comment Use code tags, see PM, thanks.


---------- Post updated at 04:40 PM ---------- Previous update was at 02:49 PM ----------

Also noticed, that if there is no file present then files copied from second folder.
Otherewise scripts perform the copy from first folder only.


Smilie

Last edited by zaxxon; 11-09-2011 at 05:37 AM.. Reason: code tags
meetvipin
# 4  
Old 11-09-2011
Try starting with
Code:
cd /home/mylogin/Test2/Important_Doc/
mget *

instead. It may be that it doesn't have permissions to access one of these folders and fails.
# 5  
Old 11-09-2011
I tested individually folder by manually FTP. It's working.
Even I changed the sequence i.e. Scripts copy files for first folder - /home/mylogin/Test2/Important_Doc/. It ignores the second.

Code:
cd /home/mylogin/Test2/Important_Doc/
mget *
cd /home/mylogin/Test
mget *

Smilie
meetvipin
# 6  
Old 11-10-2011
Why not just create two scripts, one for each directory, and login twice.
Also consider using a .netrc file so that the userid and password are not stored in the script.
# 7  
Old 11-11-2011
MySQL

It's working after applying the 'pwd' just after mget *

Code:
cd /home/mylogin/Test2/Important_Doc/
mget *
pwd
cd /home/mylogin/Test
mget *

Thanks a lot
Smilie
meetvipin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy particular files from a multiple directories and paste in a new directory?

Dear all I have a multiple directories, say for example org1, org2, org3 ..... org100 and each directory having a file namely dnaG.fasta. I need to copy all the dnaG.fasta file from each directory and paste in another directory fastconcatg. Therefore, my script has to copy dnaG.fasta file from... (5 Replies)
Discussion started by: dineshkumarsrk
5 Replies

2. Shell Programming and Scripting

Copy the files in directory and sub folders as it is to another directory.

How to copy files from one directory to another directory with the subfolders copied. If i have folder1/sub1/sub2/* it needs to copy files to folder2/sub1/sub2/*. I do not want to create sub folders in folder2. Can copy command create them automatically? I tried cp -a and cp -R but did... (4 Replies)
Discussion started by: santosh2626
4 Replies

3. Red Hat

Unable to copy files due to many files in directory

I have directory that has some billion file inside , i tried copy some files for specific date but it's always did not respond for long time and did not give any result.. i tried everything with find command and also with xargs.. even this command find . -mtime -2 -print | xargs ls -d did not... (2 Replies)
Discussion started by: before4
2 Replies

4. Shell Programming and Scripting

FTP files from different directory from remote server to one directory in local

Hi All, I want to search for .log files from folders and sub folders in remote server and FTP them to one particular folder in the local machine. I dont want to copy the entire directory tree structure, just have to take all the .log files from all the folders by doing a recursive search from the... (3 Replies)
Discussion started by: dassv
3 Replies

5. Shell Programming and Scripting

Copy files from multiple directories into one directory without overwriting them

I have several directories and all those directories have .dat files in them. I want to copy all those .dat files to one directory say "collected_directory" The problem is I don't want to overwrite files. So, if two file names match, I don't want the old file to be overwritten with a new one. ... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

6. UNIX for Dummies Questions & Answers

How to copy all files into the same directory

Dear All, Again I have another simple question. :confused: I want to write a csh which can copy all files of a current directory with a new name in the same directory, I mean: If I have tree bird apple as files in a directory I want to give ,say number 007 as argument to my csh and it copies... (3 Replies)
Discussion started by: dreamer0085
3 Replies

7. UNIX for Dummies Questions & Answers

Can I copy files on remote server with ftp ?

I just realize the only way is to download and upload again.. is not possible to copy them remotely with the ftp protocol ? thanks (2 Replies)
Discussion started by: aneuryzma
2 Replies

8. Shell Programming and Scripting

ftp multiple files from same directory

Hi there Gurus, I have the following ftp script: $ more ftp_dump_arch4.sh #! /usr/bin/ksh # Constant variables HOST='xx.xx.xx.xx' USER='user' PASSWD='password' dir='/export/file' ftp_log='/tmp' ftp -n $HOST > $ftp_log/ftp.log << END user $USER $PASSWD verbose lcd $dir bin (3 Replies)
Discussion started by: lweegp
3 Replies

9. UNIX for Dummies Questions & Answers

Copy files from a directory by ftp

Hi all, I have to enable users to access a folder by ftp. Could you tell me which configurations files I must modify or create? Thanks (3 Replies)
Discussion started by: hippa77
3 Replies

10. Shell Programming and Scripting

failed to access directory thru ftp

Hi all, I am a beginner to unix and ftp too.So i request your valuable comments. Requirement: I want to put a specific file into a server(linux) and under a particular directory path in that server as /caps/details/data/ Problem : I login to that server through the command `ftp... (1 Reply)
Discussion started by: DILEEP410
1 Replies
Login or Register to Ask a Question