bash script for ftp-upload is not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script for ftp-upload is not working
# 1  
Old 01-05-2011
bash script for ftp-upload is not working

Hello everyone,

sorry for the title, most of you must getting sick of reading something like
this, but I haven't found a solution, although I found many threads according
to it.

I'm working on a bash script that connects to a network printer with ftp
where I want to upload a pdf created with fpdf, which should be printed. This bash script should later be called via cronjob.
But I've already got a problem with the first step.

I've tested the script which I found with the help of google, but my test pdf file
seems not to be fully uploaded until the script ends.

I have read, that when using a "here document", the commands should be
executed as if they were typed, but the put-command seems to be aborted as
the last few bytes seems to be missing.
I tried the sleep-command after the put,but then I receive an "?Invalid
Command" error.

the primary script:
Code:
#!/bin/bash
USER='xxx'
PASSWD='xxx'

ftp -n <<EOD
open xxx
quote USER $USER
quote PASS $PASSWD
put /path/to/test.pdf
quit
EOD
exit 0

When I do those steps in the terminal, the network printer prints my
test.pdf.

I would be very thankful if someone could help me, or can show me a
related thread. Everyting I found already, couldn't help me.

greetings
# 2  
Old 01-05-2011
Your code worked for me

I copy/pasted your code snippet into a new bash script, changed the username, password, testfile, and FTP server, then it ran just fine.

Try changing the first line to:
Code:
#!/bin/bash -xv

You can get a better idea of where it's failing.

You can't put a "sleep" between the "<<EOD" and "EOD" since FTP doesn't understand that command.

If you're missing bytes, you probably need to issue a "bin" (binary) command prior to your "put", otherwise the end-of-line character can get affected. FTP transfers over ASCII mode by default.

Code:
#!/bin/bash
USER='xxx'
PASSWD='xxx'

ftp -n <<EOD
open xxx
quote USER $USER
quote PASS $PASSWD
bin
put /path/to/test.pdf
quit
EOD
exit 0

Also, the FTP "put" command with a single argument implies the location of the local file is the same as the remote file, so if you do this:

Code:
put /path/to/file.txt

You are telling FTP to upload the local file /path/to/file.txt to the FTP's remote directory /path/to/, which may not exist. Perhaps you mean to do this:

Code:
put /path/to/file.txt file.txt

-dufftime
This User Gave Thanks to dufftime For This Post:
# 3  
Old 01-06-2011
Quote:
FTP transfers over ASCII mode by default.
FTP defaults to "binary". Try the ftp "status" command just after logging in.
Many versions of ftp will try to deduce the transfer type based on the MSDOS style filename (e.g. .txt) unless told otherwise. Always good to postively state ascii or binary.


Let's check that the script is in the correct unix text file format. This sed is designed to make spaces and control characters visible.
Code:
sed -n l scriptname

Many laser printers need a formfeed character at the end of the document. Otherwise they wait until the connection times out before emptying the print buffer.
# 4  
Old 01-06-2011
Thank you both so much!

It works now, at least when I try it from my laptop.
I'll try it over night now on the server with the cronjob.

Although the terminal "told" me, that it was using binary mode when applying
my primary script, the idea with the bin-command before using the
put command seemed to make the difference.

You, sir, made my day.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Html upload file to bash script

I am trying to upload a file to the server using bash script in html form. <FORM NAME="FORM1" METHOD="post" enctype="multipart/form-data" ACTION="/cgi-bin/UPLOAD.sh"> <INPUT type="file" name="DOCFILE" id="DOCFILE" accept=".jpg,.tif,.pdf"> </FORM> How can I able to access the file in... (8 Replies)
Discussion started by: Naz
8 Replies

2. Shell Programming and Scripting

FTP script not working

Hi, I have one FTP script which simply sends the file to target server via netrc.it used to work as normal for years.recently target server IP got changed , same has been updated in .netrc but unable to connect it via FTP though netwrk guys already opened the port 21,20 and 22 . NETRC... (7 Replies)
Discussion started by: Riverstone
7 Replies

3. Shell Programming and Scripting

FTP in shell script and selecting files for upload

Hi, Im a newbie with programming and shell scripting. Im running OSX/Mac and Darwin. I would like to create a shell script that would : 1. Search a Volume and directory (including subdirectories) for a file that : * filename ends with ”_Highres.pdf” and * the file creation date of... (8 Replies)
Discussion started by: NickeZ28
8 Replies

4. Shell Programming and Scripting

Script to upload latest file to other server via FTP

Hello, I have a script that finds the latest version of a file in a folder on my Minecraft server. I'm trying to come up with something that will then FTP that file over to my fileserver. Here's what I have that finds the newest file: find /home/mc/archive/sbhouse -type f -mtime +45 -exec... (7 Replies)
Discussion started by: nbsparks
7 Replies

5. Shell Programming and Scripting

FTP Upload

Can any one help in writing FTP upload script using bash .. with specific port -oPort=62022 #/bin/bash FTPU="username" # ftp login name FTPP="password" # ftp password FTPS="localhost.com" # remote ftp server FTPF="/test" # remote ftp server directory for $FTPU & $FTPP port="2345"... (3 Replies)
Discussion started by: ram5019
3 Replies

6. Shell Programming and Scripting

FTP upload

Hi All, I am new to this forum and i need help from you . Here i want to get a mail conformation when ever the file was uploaded to FTP server.Here is my FTP script . Can any one plz help me how to get a mail confirmation weather the file was uploaded or not. #!bin/sh HOST='192.168.2.85'... (4 Replies)
Discussion started by: qfund
4 Replies

7. Shell Programming and Scripting

Shell Script to monitor folder and upload found files via FTP

Hi everyone! I'm in a need of a shell script that search for all files in a folder, move all those files to a temp folder, and upload those files via FTP. When the file transfer via FTP completes successfully, the file is moved to a completed folder. In case any of those files fails, the file... (4 Replies)
Discussion started by: pulsorock
4 Replies

8. Shell Programming and Scripting

ftp put in shell script -- whole file doesn't upload

Hi I'm having some trouble with a bash shell script that I'm writing. In the script, I'm trying to upload a file to a backup repository using ftp, but the whole file doesn't get uploaded. This is the file's properties at the start (I've highlighted the file size in red): -rw-r--r-- 1 root... (2 Replies)
Discussion started by: Viola
2 Replies

9. Linux

upload FTP

I have a ftp server up , however when I upload a file from my desktop to the server I get this message: ftp> get uploadtest.txt Local: uploadtest.txt Remote: uploadtest.txt 227 passive Mode ( 192,168,0,1,190,75) 550 Failed to open file ftp> (3 Replies)
Discussion started by: keliy1
3 Replies

10. UNIX for Advanced & Expert Users

Ftp Upload Folder

Hi! I'd like to upload a complete folder with subfolders with put. At the moment I always get the err-msg: aboutme: not a plain file Could anyone help me?? Thanx (3 Replies)
Discussion started by: roberthawke
3 Replies
Login or Register to Ask a Question