Visit The New, Modern Unix Linux Community

How to set file transfer in binary mode in SFTP using Expect?

Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to set file transfer in binary mode in SFTP using Expect?
# 1  
How to set file transfer in binary mode in SFTP using Expect?

The below is my script.

        spawn /usr/bin/sftp -o Port=$PORT $USER@$HOST
        expect "sftp>"
        expect "password:"
        set timout 15
        send "$password\r"
        expect "sftp>"
        send "lcd $remotedir\r"
        expect "sftp>"
        send "cd $lob\r"
        expect "sftp>"
        send "mkdir $newdir\r"
        expect "sftp>"
        send "cd $newdir\r"
        expect "sftp>"
        send "mput *.dat\r"
        expect "sftp>"
        log_file -noappend ls.out
        send  "ls\n"
        expect "sftp>"
        send "bye\r"

Moderator's Comments:
Mod Comment Please use code tags
# 2  
In binary transfers (default i.e., what you have), data is transferred to the server byte-by-byte with no data
conversion. The \r makes the file a windows text file, which is your problem. I think. Depends on how the system that receives the file looks at it. Some systems use the file extension.

I'm not sure about this one line: log_file -noappend ls.out which seems to be non-standard sftp and/or non-standard shell.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #466
Difficulty: Medium
NTP was designed by David L. Mills of the University of New York.
True or False?

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

File transfer using SFTP

Hi, I want to a transfer file from remote machine to a local machine using SFTP where both my local and remote machines are Ubuntu machines.So i wanted to write a unix bash script which uses SFTP command to transfer the file from remote to local machine. My remote server is ... (14 Replies)
Discussion started by: shree11
14 Replies

3. Shell Programming and Scripting

Passwordless file transfer using sftp

Hello all, I have a requirement, in which we need to stage a package to Unix remote server in an automation (we cant use ssh key generation) , do u have any idea how we can transfer the package to remote server using sftp .if you have any script plz share it to me (4 Replies)
Discussion started by: Ramji Sundaram
4 Replies

4. Shell Programming and Scripting

Expect script file transfer failure

I use expect to spawn an sftp file transfer. On occasion the transfer fails or doesn't complete correctly, resulting in: "sftp> cd /returns sftp> rename /returns/TESTFILE.TXT /returns/archive/TESTFILE.TXT Couldn't rename file "/returns/TESTFILE.TXT" to "/returns/archive/TESTFILE.TXT": Failure... (0 Replies)
Discussion started by: tjb1959
0 Replies

5. Shell Programming and Scripting

SFTP with ASCII file transfer

Hello - I have text file and need to load the data in Oracle through sqlloader. I need to move this file to unix server and load into oracle. When i SFTP(unfortunately i do not have FTP) to unix box, each line is appended with ControlM character... since it is transferring in BINARY... (4 Replies)
Discussion started by: govindts
4 Replies

6. Shell Programming and Scripting

SFTP file transfer mode question

I am having trouble viewing a file in ASCII after doing a 'get' using SFTP. It appears to have come across as machine language. Does the file have to be in ASCII format prior to the 'get' or is there a way to convert it to ascii after I get it onto my server? I have read where the secure file... (0 Replies)
Discussion started by: wsiefkas
0 Replies

7. Shell Programming and Scripting

sftp file transfer

hi i am trying to login to remote server using SFTP Protocol and trying to upload a file butit is asking for the password. Note: I am trying to connect to FrontEnd server sftp SFTREGUP1@ Connecting to Password Authentication Password: Please help (14 Replies)
Discussion started by: Satyak
14 Replies

8. UNIX for Advanced & Expert Users

sftp command for file transfer

hi, I need to sftp a file from one unix system to another unix system. eg: filename is test.txt servername : abc@xyz please give me the sftp command for that. thanks in advance.. mohan.p (2 Replies)
Discussion started by: mohanpadamata
2 Replies

9. IP Networking

Transfering file through FTP through Binary Mode

Hi, I'm uploading files using internet explorer. 1.Open internet explorer 6.0 2.Open site like 3.Copy files The files which I'm copying are basically zip files. What is the default transfer mode, I mean ASCII/BINARY ???. The problem I'm facing, while extracting these... (4 Replies)
Discussion started by: ronald_brayan
4 Replies

10. Programming

Binary File Transfer

I have written a program in C to transfer files between 2 machines . The program uses UDP . At the server the file is saved in the current directory using fwrite . Everything seems to be working exept for one problem . The binary files gets corrupted on the server . Thats is doing a diff of the... (2 Replies)
Discussion started by: DPAI
2 Replies

Featured Tech Videos