Friday, 5 July 2024

Download files from a remote SFTP server to local machine and upload to remote server using command prompt - putty

 

Please follow below steps to login and download files from remote server and upload to another remote server.


This guide will explain how to login to remote server using SFTP command and SSH key instead of password.


 

Local Machine - 

1. Create a dir to download the files from Source remote server and upload the same files to destination remote server 

 

[aceuser@host2ace01 ~]$ mkdir Sorce-Dest-manual-Copy

[aceuser@host2ace01 ~]$ chmod 777 Sorce-Dest-manual-Copy

[aceuser@host2ace01 Sorce-Dest-manual-Copyl]$ pwd

/home/aceuser/Sorce-Dest-manual-Copy

 

2. Login to Source server FOR first user and download the files

 

[aceuser@host2ace01 Sorce-Dest-manual-Copy]$ sftp -i /home/aceuser/.ssh/id_rsa_iib userid_01@host.com

Connected to userid_01@host.com.

sftp> ls

JobFamily_20240705.csv        JobType_20240705.csv          Org_20240705.csv              Person_20240705.csv

_staged

sftp> ls -ltr

drwxrw-rw-   1 user     group           0 Feb  1 01:57 _staged

-rw-rw-rw-   1 user     group         358 Jul  5 00:00 JobFamily_20240705.csv

-rw-rw-rw-   1 user     group      453669 Jul  5 00:00 JobType_20240705.csv

-rw-rw-rw-   1 user     group       96756 Jul  5 00:00 Org_20240705.csv

-rw-rw-rw-   1 user     group     2958835 Jul  5 01:00 Person_20240705.csv

sftp> get *20240705.csv

Fetching /JobFamily_20240705.csv to JobFamily_20240705.csv

/JobFamily_20240705.csv                                                                                           100%  358     4.0KB/s   00:00

Fetching /JobType_20240705.csv to JobType_20240705.csv

/JobType_20240705.csv                                                                                             100%  443KB   1.2MB/s   00:00

Fetching /Org_20240705.csv to TGCS_SABAOrg_20240705.csv

/Org_20240705.csv                                                                                                 100%   94KB 637.3KB/s   00:00

Fetching /Person_20240705.csv to Person_20240705.csv

/Person_20240705.csv                                                                                              100% 2889KB   1.2MB/s   00:02

sftp>exit

 

3. Login to Source server FOR user 2 and download the files

 

[aceuser@host2ace01 Sorce-Dest-manual-Copy]$ sftp -i /home/aceuser/.ssh/id_rsa_iib userid_02@host.com

Connected to userid_02@host.com.

sftp> ls -ltr

drwxrw-rw-   1 user     group           0 Dec  6  2022 _staged

-rw-rw-rw-   1 user     group         398 Jul  5 00:00 JobFamily_20240705.csv

-rw-rw-rw-   1 user     group      273250 Jul  5 00:00 JobType_20240705.csv

-rw-rw-rw-   1 user     group       22521 Jul  5 00:00 Org_20240705.csv

-rw-rw-rw-   1 user     group       39794 Jul  5 00:00 Loc_20240705.csv

-rw-rw-rw-   1 user     group     2752691 Jul  5 01:00 Person_20240705.csv

sftp> get *20240705.csv

Fetching /JobFamily_20240705.csv to JobFamily_20240705.csv

/JobFamily_20240705.csv                                                                                           100%  398     4.9KB/s   00:00

Fetching /JobType_20240705.csv to JobType_20240705.csv

/JobType_20240705.csv                                                                                             100%  267KB 560.3KB/s   00:00

Fetching /Loc_20240705.csv to Loc_20240705.csv

/Loc_20240705.csv                                                                                                 100%   39KB 192.9KB/s   00:00

Fetching /Org_20240705.csv to Org_20240705.csv

/Org_20240705.csv                                                                                                 100%   22KB 250.5KB/s   00:00

Fetching /Person_20240705.csv to Person_20240705.csv

/Person_20240705.csv                                                                                              100% 2688KB 828.5KB/s   00:03

sftp>exit

 

4. List the files downloaded from Source to local machine 

 

[aceuser@host2ace01 Sorce-Dest-manual-Copy]$ ls -ltr

total 6468

-rw-------. 1 aceuser mqbrkrs    1671 Jul  5 02:28 id_rsa_iib

-rw-r--r--. 1 aceuser mqbrkrs     358 Jul  5 03:12 JobFamily_20240705.csv

-rw-r--r--. 1 aceuser mqbrkrs  453669 Jul  5 03:12 JobType_20240705.csv

-rw-r--r--. 1 aceuser mqbrkrs   96756 Jul  5 03:12 Org_20240705.csv

-rw-r--r--. 1 aceuser mqbrkrs 2958835 Jul  5 03:12 Person_20240705.csv

-rw-r--r--. 1 aceuser mqbrkrs     398 Jul  5 03:13 JobFamily_20240705.csv

-rw-r--r--. 1 aceuser mqbrkrs  273250 Jul  5 03:13 JobType_20240705.csv

-rw-r--r--. 1 aceuser mqbrkrs   39794 Jul  5 03:13 Loc_20240705.csv

-rw-r--r--. 1 aceuser mqbrkrs   22521 Jul  5 03:13 Org_20240705.csv

-rw-r--r--. 1 aceuser mqbrkrs 2752691 Jul  5 03:13 Person_20240705.csv

[aceuser@host2ace01 Sorce-Dest-manual-Copy]$

 

 

 

5. Login to Destination remote server to upload/push the files -


[aceuser@host2ace01 Sorce-Dest-manual-Copy]$ sftp -i /home/aceuser/.ssh/id_rsa_iib -oPort=22222 destuserid@remotehost.com

Connected to destuserid@remotehost.com.

sftp> ls

sftp> cd prod/inbound/

sftp> put *20240705.csv

Uploading JobFamily_20240705.csv to /client/prod/inbound/JobFamily_20240705.csv

JobFamily_20240705.csv                                                                                            100%  398    26.2KB/s   00:00

Uploading JobType_20240705.csv to /client/prod/inbound/JobType_20240705.csv

JobType_20240705.csv                                                                                              100%  267KB   3.0MB/s   00:00

Uploading Loc_20240705.csv to /client/prod/inbound/Loc_20240705.csv

Loc_20240705.csv                                                                                                  100%   39KB   1.0MB/s   00:00

Uploading Org_20240705.csv to /client/prod/inbound/Org_20240705.csv

Org_20240705.csv                                                                                                  100%   22KB   1.0MB/s   00:00

Uploading Person_20240705.csv to /client/prod/inbound/Person_20240705.csv

Person_20240705.csv                                                                                               100% 2688KB  31.0MB/s   00:00

UploadingJobFamily_20240705.csv to /client/prod/inbound/JobFamily_20240705.csv

TGCS_SABAJobFamily_20240705.csv                                                                                            100%  358    23.1KB/s   00:00

Uploading JobType_20240705.csv to /client/prod/inbound/JobType_20240705.csv

JobType_20240705.csv                                                                                              100%  443KB   4.8MB/s   00:00

Uploading Org_20240705.csv to /client/prod/inbound/Org_20240705.csv

Org_20240705.csv                                                                                                  100%   94KB   2.9MB/s   00:00

Uploading Person_20240705.csv to /client/prod/inbound/Person_20240705.csv

Person_20240705.csv                                                                                               100% 2889KB  41.1MB/s   00:00

sftp>

 

 

6. Files are uploaded manually to Destination server under prod/inbound dir as per the ACE flow process.


[aceuser@host2ace01 Sorce-Dest-manual-Copy]$ sftp -i /home/aceuser/.ssh/id_rsa_iib -oPort=22222 destuserid@remotehost.com

Connected to destuserid@remotehost.com.

sftp> cd prod/inbound/

sftp> ls -ltr

 

-rw-r--r--    1 669      504           398 Jul  5 07:21 JobFamily_20240705.csv

-rw-r--r--    1 669      504        273250 Jul  5 07:21 JobType_20240705.csv

-rw-r--r--    1 669      504         39794 Jul  5 07:21 Loc_20240705.csv

-rw-r--r--    1 669      504         22521 Jul  5 07:21 Org_20240705.csv

-rw-r--r--    1 669      504       2752691 Jul  5 07:21 Person_20240705.csv

-rw-r--r--    1 669      504           358 Jul  5 07:21 JobFamily_20240705.csv

-rw-r--r--    1 669      504        453669 Jul  5 07:21 JobType_20240705.csv

-rw-r--r--    1 669      504         96756 Jul  5 07:21 Org_20240705.csv

-rw-r--r--    1 669      504       2958835 Jul  5 07:21 Person_20240705.csv

sftp> pwd

Remote working directory: /client/prod/inbound

sftp>

 

No comments:

Post a Comment

Sending file as multi-part MIME over http in ACE - esql

  How to send a file over http as a multipart mime? Below are the steps to do that - 1. Make sure you have the data encryption in place for ...