Sunday, November 2, 2014

SOAP with Attachments

#!/usr/bin/perl

use Net::FTP;
use SOAP::Lite;

my $server="xxxxx";

my $user="xxxx";

my $pass="xxxx";

my $path="/xx/xxx/xxx/xxxx";

if($ftp = Net::FTP->new("$server", Timeout=>60, Debug=>0)){
if($ftp->login("$user","$pass")){
$ftp->binary();
if($ftp->cwd("$path")){
open($remote_file_handle, '>', \$remote_file_content);
$ftp->get("upload.txt", $remote_file_handle) or die "get failed ", $ftp->message;
close($remote_file_handle);
}
}
}

@result = SOAP::Lite
       -> service("http://servername/soap/xxx.wsdl")
       -> on_fault(sub { my($soap, $res) = @_; die ref $res ? $res->faultstring : $soap->transport->status,})
       -> SOAPCall(
SOAP::Data->name(stream=>$remote_file_content)->type('string'));

use Data::Dumper;

print Dumper @result;


Thursday, July 3, 2014

Net::FTP Commands


# Create a new Net::FTP object, changing the
# timeout to 60 seconds
$ftp = Net::FTP->new($CPANhost, Timeout => 60)
or die "Cannot contact $CPANhost: $!";
 $ftp = Net::FTP->new("$ftp_site", Debug => 0)
    or die "Cannot connect to $ftp_site: $@\. ", $ftp->message;
$ftp2 = Net::FTP->new(Host =>$hostname2, Debug => 1, Port => 21,Passive => 0);
#-- login
$ftp->login($username,$password) or die "Login failed: $@";
$ftp = Net::FTP->new("ftp.microsoft.com",Timeout=>240,                Firewall=>"ftpproxy.sailor.com",FirewallType=>2);
#-- chdir to $ftpdir
$ftp->cwd($ftpdir) or die "Can't go to $ftpdir: $!";
#-- download file
$ftp->get($file) or die "Can't get $file: $!";
$$Connection{sourceConnection}->get
("$arg{SourcePath}/$arg{SourceFile}",
"$lcdPath/$lcdFile")
#-- close ftp connection
$ftp->quit or die "Error closing ftp connection: $!";
# Retrieve a recursive directory listing          
@ls = $ftp->ls('-lR');
# We probably want binary,            
# although some files may be ASCII
$ftp->binary();
# Send the RETR command to the source server          
# and obtain a file descriptor 
$ffile = '/pub/testfile'; 
$fdf = $ftpf->retr($ffile)
    or die "Can't retrieve '$ffile': $!";
# Send the STOR command to the destination server               
# and obtain a file descriptor 
$sfile = '/pub/outfile'; 
$fdd = $ftpd->stor($sfile) or die "Cannot store '$sfile': $!";
print $ftp->ls($home),"\n";
$ftp->delete([filename])
Deletes the specified file from the server.
## Deleting a file in remote directory
           
$ftp->delete("filerenamed.txt") ||
                   warn
                     "Unable to delete file:", $ftp->message;
$ftp->delete( 'stuff.js' );
$ftp->mdtm(file)
Returns the modification time of remote file file.
$ftp->mkdir(dir[, recursive])
Makes a new directory. Arguments are:
The new directory name
recursive
If true, creates all directories in the path as needed
 $ftp->mkdir("$folder")
    or die "Cannot create directory $folder. ", $ftp->message;
$
ftp->pwd(  )
Returns the current directory path.
$ftp->rename(file1, file2)
Renames a file on the server. Arguments are:
The old name of the file
file2
The new name of the file
## Rename a file in remote directory
           
$ftp->rename("TestFtpMod.pl","filerenamed.txt") ||
warn
"Unable to rename file:", $ftp->message;
Remove the directory with the name DIR. If RECURSE is true then rmdir 
will attempt to delete everything inside the directory.
## Deleting a directory including its contents
           
$ftp->rmdir($newdir, true) ||
warn
"Unable to remove directory:", $ftp->message;
$
ftp->size(file)
Returns the size of file file in bytes.
Ex: $rsize = $ftp->size($myfile);
$_srcSize = $$Connection{sourceConnection}->size
("$arg{SourcePath}/$arg{SourceFile}");
$_destSize = $$Connection{destinationConnection}->
size("$lcdPath/$lcdFile");
$ftp->put("$folder/$file.Z")
    or die "Put failed - $folder. ", $ftp->message;
 $ok = $ftp->response();
Tell the server that you wish to store a file. FILE is the name of 
the new file that should be created.
my @sent_files = Net::FTP::Simple->send_files({
username => $username,
password => $password,
server => $server,
remote_dir => '/ftpdir/',
debug_ftp => 1,
files => [ 'myfile1.txt','myfile2.xml','myfile2.csv', ],
});
my @remote_files = Net::FTP::Simple->list_files({
username => $username,
password => $password,
server => $server,
remote_dir => '/ftpdir/',
debug_ftp => 1,
});
pasv_xfer ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
This method will do a file transfer between two 
remote ftp servers. If DEST_FILE is omitted then 
the leaf name of SRC_FILE will be used.
Ex1: $$Connection{sourceConnection}->pasv_xfer
("$arg{SourcePath}/$arg{SourceFile}", $$Connection{destinationConnection},
"$lcdPath/$lcdFile")
Ex2: $ftpin->pasv_xfer("ApJ306023.xml", 
$ftpdest);
$
ftp->quot(cmd[,args])
Sends a literal FTP protocol command to the 
server and waits for a response. Returns the 
most significant digit of the response code.
supported
          
$ftp->supported(cmd)
Returns true if the server supports the 
command cmd
type
          
$ftp->type(type[,args])
Changes the type of data transfer. Possible 
types are ascii, ebcdic, byte, and binary. 
The value of args depends on the type.
SrcCase
 On a "Put" transfer setting this to "1" 
will override the default behavior of 
converting the path/file to lower case.
DestCase
 On all transfer types setting this to "1" 
will override the default behavior of 
setting the path/file to lower case.