File Listing from remote to loca directory using SFTP


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File Listing from remote to loca directory using SFTP
# 1  
Old 04-17-2012
File Listing from remote to loca directory using SFTP

Hello,

Using ftp i was able to get a directory listing to local directory.

Code:
ftp - i <host_name>
ftp <user>
ftp <password>
dir <dir>
200 PORT command successful
150 Opening ASCII mode data connection for file list
-rw-rw-r--   1 <uuu>  <kkk>   160384 Apr 13  19:38 walmart.txt
226 Transfer complete
ftp> lcd <local_dir>
ftp> dir walgreens.txt lcd
200 PORT command successful
150 Opening ASCII mode data connection for file list
226 Transfer complete
ftp> bye


Can someone please tell mw how do I achieve the same using sftp.

The provider changed to sftp from ftp. the above commands do not work when I tried after connecting using sftp to get directory listing to local dir to know when the files were actually dropped.

Thanks
Pavan

Last edited by Corona688; 04-17-2012 at 03:41 PM..
# 2  
Old 04-17-2012
First, you must arrange keys so you can login passwordlessly. You do this the same way you do for ssh, and there's tutorials all over the internet from that. This is safer and more convenient than keeping passwords inside your scripts, especially because sftp no longer allows this.

Then you can just sftp in and feed it commands without worrying about login information like such:

Code:
sftp username@host <<EOF
ls mydir
bye
EOF

Some systems may need sftp -b.
# 3  
Old 04-17-2012
File Listing from remote to loca directory using SFTP

I am able to connect to sftp without using any password.

Code:
sftp <port>  <user>@<hostname>
sftp> cd <remote dir>
sftp> lcd <local dir path>
sftp> dir <remote dir> lcd
sftp>


Now I login to <local dir path> and I can't find the file. I am trying to find when the file was actually dropped at sftp remote server.

Thanks
pavan

Last edited by Scott; 04-17-2012 at 04:16 PM.. Reason: Use code tags, PLEASE...
# 4  
Old 04-17-2012
pava_test is effectively asking whether this universal ftp syntax works with sftp ? :
Code:
dir <remote dir> <directory_list_file>

The ftp syntax drops a directory listing to a local file which is really useful.
Anybody know. Does it work with sftp ?


(Whenever I have possible sftp I also have scp and there is no contest.)
# 5  
Old 04-17-2012
File Listing from remote to loca directory using SFTP

yes, I am asking if
Code:
dir <remote dir> <directory_list_file>

works for sftp. it works with ftp. (i tried and it did not work for me using sftp)

I am not aware if there are any alternate commands for sftp to perform similar commands in ftp.

I don't intend to download entire file just the directory listing to the local directory using sftp.

Thanks
Pavan

Moderator's Comments:
Mod Comment ==> How to use code tags !!!!!!!!! (click me) <==

Last edited by Scrutinizer; 04-17-2012 at 05:01 PM.. Reason: code tags
# 6  
Old 04-17-2012
@ pavan_test
Please don't cover my post.

Any sftp experts out there know whether the known good ftp syntax posted earlier works with sftp? Otherwise we just need to use unix Shell to redirect the output from the sftp dir command to a file suitable for further processing.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need help with listing file name and modified date on a huge directory

hi, We have a huge directory that ha 5.1 Million files in it. We are trying to get the file name and modified timestamp of the most recent 3 years from this huge directory for a migration project. However, the ls command (background process) to list the file names and timestamp is running for... (2 Replies)
Discussion started by: subbu
2 Replies

2. UNIX for Beginners Questions & Answers

SFTP file check through a remote host

Hi all, posting my first time, hope not breaking posting rules with it, if yes, let me know. I'm trying to build a script to check a file in an sftp server through a remote server. The intention is to check the file in a sftp host, and if the file is found or not, it should send an email.... (4 Replies)
Discussion started by: MrShinyPants
4 Replies

3. UNIX for Beginners Questions & Answers

Listing a file/directory with 7 letters long

I know that I can use wild cards:ls ???????to list files 7 characters long, but how do i omit the .?! and spaces? Please use CODE tags when displaying sample input, sample output, and code segments. (2 Replies)
Discussion started by: hiya54
2 Replies

4. UNIX for Dummies Questions & Answers

SFTP to delete remote file

Hi guys In this scenario, i have been able to transfer the file from a remote server to my local server, but how to delete the file from remote server once its copied. I am using this command MYFILE=/tmp/MyFiLe.$$ echo rm FROM_DIR/K* >$MYFILE then sftp -b $MYFILE rm -f $MYFILE and I have... (1 Reply)
Discussion started by: rubel
1 Replies

5. Shell Programming and Scripting

SFTP problem......File not getting from Remote server

Hi, We are using one unix script which is using sftp command and connect to remote server and get some file form remote server. some time after running this script we are not getting any file . Could you please tell us detailed validation that is there any problem with... (6 Replies)
Discussion started by: maheshkumar93@g
6 Replies

6. UNIX for Dummies Questions & Answers

File listing from remote to local directory

Hello, I have a file at remote server. I have to select only current day's files that are dropped on ftp server. The files do not have date or timestamp on them. so I plan to get the file listing from remote server to the local server. Based on file listing date I can find out when the files... (2 Replies)
Discussion started by: pavan_test
2 Replies

7. Shell Programming and Scripting

listing Directory chronologically based on part of file name

hi Everbody, I had file names as shown file_01_20101104.txt file_01_20101105.txt file_02_20101104.txt file_01_20101205.txt file_03_20101104.txt file_02_20101105.txt Now i want to list them based on the date in the file name as shown... file_01_20101104.txt file_02_20101104.txt... (3 Replies)
Discussion started by: Reddy482
3 Replies

8. Shell Programming and Scripting

Checking the file in remote server using SFTP

Hello, I would appreciate if any one can help me on this. The below script start running at 12:30AM. Every 5 min, i go and check the remote site. If i see filewatch.txt over there, then i need to call another shell script and load the data into database. If i don't see that file, then i have to... (2 Replies)
Discussion started by: govindts
2 Replies

9. Shell Programming and Scripting

creating a file on remote directory using sftp

Hi, My requirement is to sftp a file from one server to another.After the file is completely transferrred, i should be able to create a text(dummy) file on the remote directory. How could this be accomplished. Any suggestions? (1 Reply)
Discussion started by: borncrazy
1 Replies

10. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question