Writing to remote file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Writing to remote file
# 1  
Old 09-02-2008
Writing to remote file

hello All,

I have the login name and pasword. I want to know how to use this info and open a file and write to it.
Ex: login: expr
pasword: xxxx
file: /expr/tmp.txt

I know how to use ftp (use Net::FTP) and upload files but I want to know how to write to a file.

Thanks,
# 2  
Old 09-02-2008
Unless the remote file is on a network mounted filesystem (like NFS) there is no simple way.

You can
1. ftp the file to your local directory
2. write the file
3. ftp it back again.

Also try ssh - you can issue remote commands like
echo "something" >> /path/to/remotefile
which write the file without having to drag it back and forth over the network.

NET::ftp is perl. Advanced programming in perl will let you create a client server app using sockets. See perldoc IO::Socket - you can create a client/server app over tcp with just that.
# 3  
Old 09-02-2008
ftping it back and fro will be time consuming as the ftp time will vary depending on file size.
I wil try the ways metioned
thanks.
# 4  
Old 09-23-2008
Does any one know how to use Net::FTP (Net::FTP->appe(FILE)) to write contents to a remote file.
# 5  
Old 09-23-2008
Code:
use strict;     
use Net::FTP;

my $host = "my.server";
my $user = "user";
my $password = "password";

my $f = Net::FTP->new($host) or die "Can't open $host\n";
$f->login($user, $password) or die "Can't login to $user in\n";

my $dir = "my/dir";

$f->cwd($dir) or die "Can't change working directory to $dir\n";

my $file_to_put = "somefile";
$f->binary();
# use this to get a file.
$f->get($file_to_get) or die "Can't get $file from $dir\n";
#use this to put a file to server
$f->put($file_to_put) or die "Can't put $file into $dir\n";
$f->quit;

Did you mean $f->append(localfile,remote); This is probably not what you want. It takes the full contents of localfile and adds all of it to the end of the remotefile. just like this does:
Code:
cat file2 >> file1

now file1 = all of file + all of file2
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to store remote variable from remote cat file ??

I am trying to cat on a file located on remote server and assign it to remote variable. I have both local and remote variables. Running below script from local. test.sh J_NAME=XXX2 J_IP=XXX ssh $J_IP "ps auxw |grep java | grep -v grep |grep $J_NAME | awk '{print ... (2 Replies)
Discussion started by: oraclermanpt
2 Replies

2. UNIX for Dummies Questions & Answers

Syslog Messages from Remote Server are not writing to Log File Anymore

Hello All, Server: SUSE Linux Enterprise Server 11.3 (x86_64) Syslog-ng Version: syslog-ng 2.0.9 We have configured a Cisco router to send it's log messages to this server listed above. This has been working just perfectly for the last couple months, but we had never setup the log... (9 Replies)
Discussion started by: mrm5102
9 Replies

3. Shell Programming and Scripting

awk - writing matching pattern to a new file and deleting it from the current file

Hello , I have comma delimited file with over 20 fileds that i need to do some validations on. I have to check if certain fields are null and then write the line containing the null field into a new file and then delete the line from the current file. Can someone tell me how i could go... (2 Replies)
Discussion started by: goddevil
2 Replies

4. UNIX for Dummies Questions & Answers

Writing a script that will take the first line from each file and store it in an output file

Hi, I have 1000 files names data1.txt through data1000.txt inside a folder. I want to write a script that will take each first line from the files and write them as output into a new file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

5. UNIX for Dummies Questions & Answers

Need help in not fetching a file while file writing operation is not completed

Hi All, We have a Unix program in oracle when we run the program this connects to specified ftp and will get the file into local server. We are facing a problem like when file writing operations is not completed, this program is getting the incomplete file. Could anyone please help me... (2 Replies)
Discussion started by: world.apps
2 Replies

6. Shell Programming and Scripting

reading a file extracting information writing to a file

Hi I am trying to extract information out of a file but keep getting grep cant open errors the code is below: #bash #extract orders with blank address details # # obtain the current date # set today to the current date ccyymmdd format today=`date +%c%m%d | cut -c24-31` echo... (8 Replies)
Discussion started by: Bruble
8 Replies

7. Shell Programming and Scripting

Writing file name and date from LS command into a file to be imported into mysql

I am looking to do a ls on a folder and have the output of the ls be structured so that is is modificaiton date, file name with the date in a format that is compatible with mysql. I am trying to build a table that stores the last modification date of certain files so I can display it on some web... (4 Replies)
Discussion started by: personalt
4 Replies

8. Shell Programming and Scripting

Comparing rows in same file and writing the result in new file

Help needed... Can you tell me how to compare the last two couple entries in a file and print their result in new file..:confused: I have one file Check1.txt \abc1 12345 \abc2 12327 \abc1 12345 \abc2 12330 I want to compare the entries in Check1 and write to... (1 Reply)
Discussion started by: kichu
1 Replies

9. Shell Programming and Scripting

Searching for Log / Bad file and Reading and writing to a flat file

Need to develop a unix shell script for the below requirement and I need your assistance: 1) search for file.log and file.bad file in a directory and read them 2) pull out "Load_Start_Time", "Data_File_Name", "Error_Type" from log file 4) concatinate each row from bad file as... (3 Replies)
Discussion started by: mlpathir
3 Replies

10. UNIX for Dummies Questions & Answers

Problem writing file path to txt file

if test -z "$1" then echo "you must give a filename or filepath" else path=`dirname $1` f_name =`basename $1` if path="." then path=`pwd` fi fi cat $f_name $path >> index.txt The only problem I am encountering with this is writing $path to index.txt Keeps going gaga: cat:... (1 Reply)
Discussion started by: Vintage_hegoog
1 Replies
Login or Register to Ask a Question