Visit Our UNIX and Linux User Community


How to get user to choose files to be copied to FTP server?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get user to choose files to be copied to FTP server?
# 1  
Old 08-20-2013
How to get user to choose files to be copied to FTP server?

Hey all. I'm writing a script to automatically login to a router, change directories to where crashfiles are located, then listing all files in that directory. This is where I'm at so far and wish to have some user interaction to choose the files.

What I am trying to do is list the files and get the user to choose which files to be copied over to the FTP server including a file name change which will also include adding a case number to the beginning of the file to be copied as part of the file name change sequence.

List files
Ask users which files to be copied
Ask user for case number(enter case number and append to front of original file name. This will not be changing the name on the current server but changing the file name during the copying process.)
And then copy ALL files chosen over to the FTP server with the new file name.

What is the best way to do this?
This is what I got so far.

Code:
expect "#"


send "cd /md\r"
expect "#"
send "dir\r"
set files ""
expect {
        -re "(\[^\n]+)\n" {
                set line [ string trim $expect_out(1,string) ]
                if { [llength $line ] > 7  } {
                  send_user "Hey I found a file its called : [ lindex $line 8 ]\n"
                  lappend files [ lindex $line 8 ]
                }
                exp_continue
        }
        "#" {}


}



foreach f $files {
send_user "$f\n"

}




interact

and the output when I run script is as follows

Code:
[local]#cd /md
Current directory is now /md
[local]#dir
Contents of /md/
total 150372
drwxrwxrwx  2 root  0       512 Jun 28 21:52 issu
-rw-r--r--  1 root  0   1048444 Jun  5 17:02 loggd_ddbg.bin
-rw-r--r--  1 root  0   1048444 Jun  5 17:02 loggd_dlog.bin
-rw-r--r--  1 root  0  57773225 Jun  5 17:02 rdb_crash.out
-rw-r--r--  1 root  0    234581 Aug 19 20:49 file.cfg
-rw-r--r--  1 root  0  16777216 Jun 28 21:52 rtdb.sav
[local]#Hey I found a file its called : issu
Hey I found a file its called : loggd_ddbg.bin
Hey I found a file its called : loggd_dlog.bin
Hey I found a file its called : rdb_crash.out
Hey I found a file its called : file.cfg
Hey I found a file its called : rtdb.sav
issu
loggd_ddbg.bin
loggd_dlog.bin
rdb_crash.out
file.cfg
rtdb.sav

[local]#


Last edited by Gouda; 08-20-2013 at 08:29 PM..
# 2  
Old 08-21-2013
If you know the credentials, you could probably do something like this shell far easier than using expect:-
Code:
#!/bin/ksh

ftp -inv target <<-EOFTP >/tmp/dirlist
user username    password
cd /md
dir
EOFTP

# Put some simple logic in here to display and select the file the user wants, perhaps in a loop and then for each file selected....

ftp -inv target <<-EOFTP >/tmp/dirlist
user username  password
cd /md
get $file
EOFTP

# End the selection loop here if you have set one up.

I think you would be very hard pressed to come up with a way of just having one FTP connection and logic within that. FTP is what it says, a File Transfer Protocol, not a user environment.



I hope that this helps,
Robin
Liverpool/Blackburn
UK

Previous Thread | Next Thread
Test Your Knowledge in Computers #25
Difficulty: Easy
Google was the first search engine developed for indexing the Internet.
True or False?

9 More Discussions You Might Find Interesting

1. Solaris

FTP-ing files from Windows server to UNIX server

I need to transfer files from a Windows server to the Unix server and have to run some shell script on it to get the required output. Is it possible to transfer files from Windows server to unix server through any shell script? If so can you please help me with the details. Thanks in... (8 Replies)
Discussion started by: ssk250
8 Replies

2. Red Hat

Files copied to FTP server not shown

I had copied 2 files to an FTP server which I deployed on my RHEL 5.8 server. The ownership I kept for the files are for the user, ftp. But, I do not see the files on the FTP location using either accessing through Windows explorer or the browser. The ftp location is ftp://10.101.17.80/incoming.... (7 Replies)
Discussion started by: RHCE
7 Replies

3. Shell Programming and Scripting

Check files copied from remote server

There is a process which copy files form unix a to unix b I would like to check whether all files copied from a to b or not ,and list which are the missing files. Is there a command to check like that (3 Replies)
Discussion started by: lalitpct
3 Replies

4. Shell Programming and Scripting

script for to take files from FTP server to UNIX server and Unzipped that files

script for to take files from FTP server to UNIX server and Unzipped that files (1 Reply)
Discussion started by: sunilamarnadh
1 Replies

5. Shell Programming and Scripting

preserving the timestamp of a file when copied from remote server to local server using ftp

Hi, I need to copy few files from remote server to local server. I write a shell script to connect to the remote server using ftp and go to that path. Now i need to copy those files in the remote directory to my local server with the timestamp of all those files shouldnt be changed. ... (5 Replies)
Discussion started by: arunkumarmc
5 Replies

6. HP-UX

FTP user information on destination server

Could any one please tell me how to check the ftp users information on the destination server ( Hp-UX ) ? Source server used to do FTP to my server ( that is destination server ) . Now , he is getting error that login is incorrect and unable to login into destination server . Please tell me how to... (3 Replies)
Discussion started by: randhir
3 Replies

7. Shell Programming and Scripting

Dowloading a File from FTP Server to a local Server where User Id's are different

Hi, The Setup is like this. I'm connecting to Unix machine from my local machine. After connecting to Unix M/c, i need to connect FTP server. Am successful in connecting to FTP server, but am not able to download the file from the ftp server to my local machine. I have different user id's and... (1 Reply)
Discussion started by: ranjith_taurean
1 Replies

8. Shell Programming and Scripting

FTP multiple files from remote server to local server

Hi, I am facing a weired problem in my FTP script. I want to transfer multiple files from remote server to local server everyday, using mget * in my script. I also, want to send an email for successful or failed FTP. My script works for file transfer, but it don't send any mail. There is... (2 Replies)
Discussion started by: berlin_germany
2 Replies

9. UNIX for Advanced & Expert Users

how to know how many user's connected to ftp and http server

i need to write a program to know how many users are presently connected to my ftp server and http server . i need to keep a count of this and this count should be available to other different software . how to make this GLOBAL so that other softwares can access this count value (7 Replies)
Discussion started by: hariprasad
7 Replies

Featured Tech Videos