File transfer from source to destinatio

######################## SCRIPT START

[oracle@hbrtl filterFiles]$ cat /zfssa/dumps/LocalToDPCFTP/File_tranfer_dpcftp.sh

cd /zfssa/dumps/Losfile ///Path where file will generate//

for FILE in $(ls -lt –time=ctime | head -n 2)

do


This content originally appeared on DEV Community and was authored by Abdullah

######################## SCRIPT START

[oracle@hbrtl filterFiles]$ cat /zfssa/dumps/LocalToDPCFTP/File_tranfer_dpcftp.sh

cd /zfssa/dumps/Losfile ///Path where file will generate//

for FILE in $(ls -lt --time=ctime | head -n 2)

do
cp ${FILE} /zfssa/dumps/filterFiles //Move current file to another folder//
done

////Actual code transfer the file//
curl --insecure --user USER:pass@123 -T //zfssa/dumps/filterFiles/*.csv sftp://dpcf.hostname.com:/FILES/
//////////END////

cd /zfssa/dumps/filterFiles

rm -rf *.csv

##################SCRIPT END
##############SCRIPT START

[oracle@hbnedm01 scripts]$ cat FileTrans.sh
SOURCE_DIR="/zfssa/Staging/LosFile"
DEST_USER="USERNAME"
DEST_HOST="hostname.com"

DEST_DIR="/FILES"

DEST_DIR="/BTG/LOS_PERF/FILES"

DEST_DIR="/FILES"

DEST_PASSWORD="PASSWORD"

Check if SSH key-based authentication is set up

ssh -q -o BatchMode=yes $DEST_USER@$DEST_HOST exit

if [ $? -ne 0 ]; then

echo "Error: SSH key-based authentication not set up for $DEST_USER@$DEST_HOST"

echo "Run: ssh-copy-id -i ~/.ssh/id_rsa.pub $DEST_USER@$DEST_HOST"

exit 1

fi

LATEST_FILE=$(find "$SOURCE_DIR" -maxdepth 1 -type f -printf "%T@ %p\n" | sort -nr | head -n 1 | cut -d' ' -f2-)

LATEST_FILE=$(ls -t "$SOURCE_DIR" | head -n 1)

if [ -z "$LATEST_FILE" ]; then
echo "Error: No files found in $SOURCE_DIR"
exit 1
fi

use expect to handle password

/usr/bin/expect << EOF
spawn scp "$LATEST_FILE" "$DEST_USER@$DEST_HOST:$DEST_DIR"

spawn sshpass -p "password@123" scp "$LATEST_FILE" "$DEST_USER@$DEST_HOST:$DEST_DIR"

expect "password:"
send "$DEST_PASSWORD\r"
expect off
EOF
if [ $? -eq 0 ]; then
echo "Successfully copied $LATEST_FILE to $DEST_HOST:$DEST_DIR"
else
echo "Error: Failed to copy $LATEST_FILE"
exit 1
fi

################## SCRIPT END


This content originally appeared on DEV Community and was authored by Abdullah


Print Share Comment Cite Upload Translate Updates
APA

Abdullah | Sciencx (2025-06-25T05:12:57+00:00) File transfer from source to destinatio. Retrieved from https://www.scien.cx/2025/06/25/file-transfer-from-source-to-destinatio/

MLA
" » File transfer from source to destinatio." Abdullah | Sciencx - Wednesday June 25, 2025, https://www.scien.cx/2025/06/25/file-transfer-from-source-to-destinatio/
HARVARD
Abdullah | Sciencx Wednesday June 25, 2025 » File transfer from source to destinatio., viewed ,<https://www.scien.cx/2025/06/25/file-transfer-from-source-to-destinatio/>
VANCOUVER
Abdullah | Sciencx - » File transfer from source to destinatio. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/06/25/file-transfer-from-source-to-destinatio/
CHICAGO
" » File transfer from source to destinatio." Abdullah | Sciencx - Accessed . https://www.scien.cx/2025/06/25/file-transfer-from-source-to-destinatio/
IEEE
" » File transfer from source to destinatio." Abdullah | Sciencx [Online]. Available: https://www.scien.cx/2025/06/25/file-transfer-from-source-to-destinatio/. [Accessed: ]
rf:citation
» File transfer from source to destinatio | Abdullah | Sciencx | https://www.scien.cx/2025/06/25/file-transfer-from-source-to-destinatio/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.