Find the answer to your Linux question:
Results 1 to 3 of 3
Guys, Can someone please help me with my problem. I am doing a FTP Shell Script but I want it to convert the fiile to binary before the FTP is ...
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Posts
    2

    HELP with FTP Shell Scripting Converting File to Binary Before FTP

    Guys,

    Can someone please help me with my problem.

    I am doing a FTP Shell Script but I want it to convert the fiile to binary before the FTP is executed.

    Notice I already have 'binary' in the script. I have tried setting the parameter to binary but my problem is that when the script is executed and the file is sent to my server, the file is still in ASCII mode when I do a 'file test.txt' command.

    Does anyone know how to transfer files in binary mode?

    Here is my simple script:

    #!/bin/sh

    filename="file.txt"
    hostname="####.com"
    username="me"
    password="1234"

    ftp -un $hostname <<EOF
    quote USER $username
    quote PASS $password

    binary
    put $filename
    quit
    EOF


    Thanks a million !

  2. #2
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101
    Putting "binary" command mode in FTP session will not change the file type to Binary. It's just a way of telling FTP that the transfer medium used will be: "binary" i.e. bit by bit transfer. Sometimes this is useful as it retains the bits/byte size of the file intact during the transfer. so, if your file size if 100 bytes then on the destination server location (where you are FTPing the file), the file size will be 100 bytes (if you don't use "binary" mode, then the file size sometime changes depending on the mode of transfer and it's compatibility between the type of file and FTP mode of transfer.

    The script that you have mentioned will transfer an ASCII file (in binary mode, NOTE: it'll not change the file into a binary file, just the transfer medium is binary during the FTP session) and after the transfer is complete, if you do a file on file.txt, then it will show you the same file type i.e. ASCII which is the type of the file.

    If you want to convert an ASCII file into binary first (first convert the file before it's being sent to FTP, you can use uuencode or gpg command) ... (i.e. it will actually become a binary file) and for that you "MUST" have to use "binary" mode of transfer in FTP session (i.e. code written between the here document word "EOF" in your script).
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  3. #3
    Just Joined!
    Join Date
    Jul 2009
    Posts
    2

    Talking RE: HELP with FTP Shell Scripting Converting File to Binary Before FTP

    Thank you buddy, that makes sense. That is what I actually wanted but didn't realize. I needed the TRANSFER to be binary but the file is staying ASCII.

    Your input is appreciated!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...