Archive

Posts Tagged ‘batch’

FTP for Developers

January 29th, 2009 Albertux 2 comments

FTP for Developers

This examples upload a simple text file for a better implementations read the API or documentation for each language or command

Curl:

curl -T filename -u username:password ftp://hostname/filename

Perl:

use Net::FTP;
$hostname = "localhost";
$username = "user";
$password = "pass";
$filename = "file.txt";
$ftp = Net::FTP->new($hostname);
$ftp->login($username,$password);
$ftp->put($filename);
$ftp->quit;

To handle errors use “or die $@” (“$ftp>message” only if login success)

PHP:

<?php
$hostname = "localhost";
$username = "user";
$password = "pass";
$filename = "file.txt";
$conn = ftp_connect($hostname);
ftp_login($conn, $username, $password);
ftp_put($conn,$filename,$filename,FTP_ASCII);
ftp_close($conn);
?>

To handle erros you can use “if(!function)”

Python:

import ftplib
hostname = "localhost"
username = "user"
password = "pass"
filename = "file.txt"
ftp = ftplib.FTP(hostname)
ftp.login(username, password)
ftp.storlines("STOR " + filename, open(filename))
ftp.quit()

To handle errors use “try” and “except” and “else”

Ruby:

require 'net/ftp'
host = 'localhost'
user = 'user'
pass = 'pass'
file = 'file.txt'
ftp = Net::FTP.new(hostname)
ftp.login(username,password)
ftp.puttextfile(filename)
ftp.close

To handle errors use “begin”, “rescue”, “else”, “ensure” and “end”.

Win32 batch:

ftp -s:settings.txt hostname

settings.txt:

username
password
put filename
bye

To handle errors use “if not %errorlevel%==0 goto :error”

Categories: network, unix/linux, web, windows Tags: , , , , ,

Using Windows ? Don't kill Yourself

October 27th, 2008 Albertux No comments

Using Windows ? Don’t Kill Yourself

Supose you are Linux user and you have a Windows system.

Alternatives: Cygwin, Mingw or Colinux

You need some (or all) of this interpreters:

Perl, PHP, Python and Ruby

Modify the %PATH%

Example you have a bin dir, on C:\ to include the executables on the %PATH% do this:

set PATH=%PATH%;C:\bin\

On Windows Vista, you can use your mouse:

computer > properties > Advances system settings > (continue) > Advanced > Enviroment Variables > System Variables > Path (edit)

Example run Kompozer on cmd.exe but no modify %PATH%

: kompozer.bat save on %WINDIR%
@"C:\Program Files\Kompozer\kompozer.exe"

Doble click on your scripts to run:

: Perl Scripts
 assoc .pl=Perl.File
 ftype Perl.File=C:\strawberry\perl\bin\perl.exe "%1" %*
 set PATHEXT=%PATHEXT%;.pl
: Python Scripts
 assoc .py=Python.File
 ftype Python.File=C:\Python26\python.exe "%1" %*
 set PATHEXT=%PATHEXT%;.py

Note:

On Windows Vista you need run cmd.exe as Administrator don’t work as normal user

Apache, PHP and MySQL ?

XAMPP and Server2Go

Notes:

XAMPP: simple, quick and easy install.

Server2Go: is great to make CD demo of a Web Application.

Using Perl or Python as CGI on Windows ?

Using Python 2.6

#!\python26\python.exe

Using Strawberry Perl:

#!\strawberry\perl\bin\perl.exe

Now your script works on http://localhost/cgi-bin/script.cgi

Categories: unix/linux, windows Tags: , , , , ,