Archivo

Entradas Etiquetadas ‘batch’

FTP for Developers

jueves, 29 de enero de 2009 Albertux 2 comentarios

FTP para Desarrolladores

En estos ejemplos se sube un archivo de texto plano para mejores implementaciones lea la API o la documentacion de cada lenguaje o comando

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;

Manejo de errores usa “or die $@” (“$ftp>message” solo cuando el login haya funcionado)

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);
?>

Manejo de errores usando “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()

Manejo de errores usando “try”, “except” y “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

Manejo de errores usando “begin”, “rescue”, “else”, “ensure” y “end”.

Win32 batch:

ftp -s:settings.txt hostname

settings.txt:

username
password
put filename
bye

Manejo de errores usando “if not %errorlevel%==0 goto :error”

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

Using Windows ? Don't kill Yourself

lunes, 27 de octubre de 2008 Albertux Sin comentarios

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:

1
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%

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

Doble click on your scripts to run:

1
2
3
4
5
6
7
8
: 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

1
#!\python26\python.exe

Using Strawberry Perl:

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

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

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