Issue in uploading file using sftp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue in uploading file using sftp
# 1  
Old 05-25-2009
Issue in uploading file using sftp

Hi

I'm using this script to upload a file from local system to sftp server.
But in the log file i'm getting an error "Error during upload"

Can you please help me out ...

### CONFIGURATION
LOCAL_DIR=/abc/out
FILE_MASK="File*.txt"
LOG_DIR=/abc/error/File_`date "+%Y%m%d%H%M%S"`.LOG
SFTP_HOST=sftp.abcd.xy
SFTP_DIR=upload
SFTP_USER=user

BACKUP_DIR=/abc/backup/out
IDENTITY_FILE=/abc/shells/.ssh/ab_xyz
ERROR_DIR=/abc/error
### END OF CONFIGURATION PART
IFS='
'
PATH=/usr/bin
get_local_file() {
if ! LOCAL_FILE=`ls $LOCAL_DIR/$FILE_MASK 2> /dev/null`; then
# file not found
echo "$LOCAL_DIR/$FILE_MASK not found" >>$LOG_DIR;
return 1
fi
return 0
}
send_file() {
REMOTE_FILE=data_`date "+%Y%m%d%H%M%S"`.csv
LOCAL_FILE=`ls $LOCAL_DIR/$FILE_MASK 2> /dev/null`
B_LOCAL_FILE=$(basename $LOCAL_FILE) # basename of local file
#echo "LOCAL_FILE: $LOCAL_FILE"
#echo "REMOTE_FILE: $REMOTE_FILE";
#echo "B_LOCAL_FILE: $B_LOCAL_FILE"
# will simulate for(i=0;i<3;i++)
for i in 1 2 3; do
#echo "COMMAND: echo \"cd upload\nput $LOCAL_FILE\nrename $B_LOCAL_FILE $REMOTE_FILE\" | sftp -o IdentityFile=$IDENTITY_FILE $SFTP_USER@$SFTP_HOST >>$LOG_DIR 2>&1"

ERR=$(echo "cd upload\nput $LOCAL_FILE\nrename $B_LOCAL_FILE $REMOTE_FILE" | sftp -o IdentityFile=$IDENTITY_FILE $SFTP_USER@$SFTP_HOST >>$LOG_DIR 2>&1)
echo "entering command 1" >>$LOG_DIR

CODE=$?
echo $CODE >>$LOG_DIR
if [ "$CODE" = "0" ]; then
break;
fi
echo "Connection failed $SFTP_USER@$SFTP_HOST" >> $LOG_DIR
done
echo $ERR >> $LOG_DIR
if [ "$CODE" != "0" ]; then
echo "connection error" >> $LOG_DIR
return 2
fi
if [ "$ERR" != "Connecting to $SFTP_HOST..." ]; then
# error during upload
echo "Error during upload" >> $LOG_DIR
return 3
fi

return 0
}
save_local_file() {
N_LOCAL_FILE=$(echo $B_LOCAL_FILE | sed -e "s/\.txt$//")
N_LOCAL_FILE=$N_LOCAL_FILE$(date "+%Y%m%d%H%M%S").txt
echo "N_LOCAL_FILE: $N_LOCAL_FILE" >> $LOG_DIR
if ! mv $LOCAL_FILE $BACKUP_DIR/$N_LOCAL_FILE; then
# creating of backup failed
return 4
fi
return 0
}
report_error() {
mv $LOCAL_DIR/*.idoc $LOCAL_DIR/IDOCS_failed_sent_from_SAP.txt
exit 1
}
report_success() {
#touch $LOCAL_DIR/IDOCS_sent_from_SAP.txt
mv $LOCAL_DIR/*.idoc $LOCAL_DIR/IDOCS_sent_from_SAP.txt
exit 0
}
main() {
get_local_file
R_CODE=$?

if [ "$R_CODE" != "0" ]; then
report_error $R_CODE
fi
send_file
R_CODE=$?
if [ "$R_CODE" != "0" ]; then
report_error $R_CODE;
fi

save_local_file
R_CODE=$?
if [ "$R_CODE" != "0" ]; then
report_error $R_CODE
fi
# else everything is ok
report_success
}
# run !
main
# 2  
Old 05-25-2009
Quote:
Originally Posted by Jaychandra
...
if [ "$ERR" != "Connecting to $SFTP_HOST..." ]; then
...
Well what is the value of ERR at this point ?

tyler_durden
# 3  
Old 05-25-2009
ERR vlaue is blank

Can any one help me in this , it's urgent

Can any one help me in this , it's urgent

Error Log:

Connecting to sftp.abcd.xy...
You are connected to sftp.abcd.xy



****USAGE WARNING****



This is a private computer system.

sftp> sftp> Uploading /abc/out/File1.txt to /upload/File1_01_02.txt
sftp> sftp>
entering command 1
0

Error during upload

Error Log:

Connecting to sftp.abcd.xy...
You are connected to sftp.abcd.xy



****USAGE WARNING****



This is a private computer system.

sftp> sftp> Uploading /abc/out/File1.txt to /upload/File1_01_02.txt
sftp> sftp>
entering command 1
0

Error during upload

is there any who can help me out ???????

is there any who can help me out ???????
# 4  
Old 05-25-2009
Can you do the sftp manually using the same parameters as you would normally do in the script?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

SFTP File transfer issue

Hi guys, Need a quick and urgent help on below issue. One of our application is try to transfer the file to another host thru sftp process My file is about 1 GB. Job is getting hung while transferring the file. So when I login as sftp and check the file system space is only in MB... (2 Replies)
Discussion started by: Vinoth Kumar G
2 Replies

2. Shell Programming and Scripting

Uploading using sftp file1 copied to file2

Hi All, i am using hp-ux server and doing mput command for uploading the multiple files. below is the code sftp hfjr@usilehrttlsd01.com cd /home/sftp_dir mput kk1 kk2 i am getting Uploading kk1 to /home/sftp_dir/kk2. problem is i am getting kk2 file only not kk1 file. when i am... (13 Replies)
Discussion started by: krupasindhu18
13 Replies

3. UNIX for Advanced & Expert Users

SFTP Resticting Only Uploading Of A File

I have setup our SFTP server: SFTP Setup: /etc/ssh/sshd_config: Subsystem sftp internal-sftp Match Group sftpusers PasswordAuthentication yes ChrootDirectory /srv/sftponly AllowTCPForwarding no X11Forwarding no ForceCommand internal-sftp Adding the... (5 Replies)
Discussion started by: metallica1973
5 Replies

4. Shell Programming and Scripting

Perl , uploading empty file.

Hi The below script used to work fine. Suddenly it's uploading empty file. I am very new to perl. Please help me to find out the problem. #!/usr/bin/perl #script: upload.pl use CGI qw/:standard/; print header, start_html('File upload'); print_form(); print_results() if... (2 Replies)
Discussion started by: Anupam_Halder
2 Replies

5. Shell Programming and Scripting

Uploading a file in ftp by culr?

I have ftp url, username and passwd. My file is named app.log. How do I upload this to my ftp server??? I read the manual but I didn't understand much...:cool: (4 Replies)
Discussion started by: hakermania
4 Replies

6. AIX

File access issue through sftp/winscp

Hi, I have SSH where I want to restrict browsing for a user "drrep" to the assigned home directory only.So I have put a entry in the sshd_config file as “AllowFiles "drrep:/fcrarch/fl02r/*" as shown in the scrren below. But due to this setting none of the users are able to login through winscp... (0 Replies)
Discussion started by: dwiravi
0 Replies

7. UNIX for Dummies Questions & Answers

help uploading directories with SFTP

Hi, I am a newbie and not really familiar with commands, I have searched the forum, but there was only one thread. That thread suggested compressing it and then decompressing it. So I am wondering, what format do I compress it to, and how do I decompress it once I uploaded it from within SFTP... (4 Replies)
Discussion started by: greetea
4 Replies

8. Solaris

Issue With File Permissions while uploading

one of the business users is ftping files into unix box using user name ftp_user, where as i am using infa_user to login into same unix box. When i am trying to access those or copy over those files from upload directory it says permission denied. Though i know the password of ftp_user to... (4 Replies)
Discussion started by: Ariean
4 Replies

9. Shell Programming and Scripting

uploading directories via SFTP

Hello All, Is there a way to upload whole directories to a machine using sftp (scp is not an option)? I have to use sftp because the machine that I am connecting to only has SFTP abilities (uploading from a linux box to a windows box). Currently I am automating a copy however right now I am... (2 Replies)
Discussion started by: mab623
2 Replies

10. Shell Programming and Scripting

Uploading a flat file into the database.

I want to upload a text file into the database. what is the command for that? Thanks in Advance. (1 Reply)
Discussion started by: Balkrishna
1 Replies
Login or Register to Ask a Question