Apr 14

FTP File Upload with C#

I use the code below for uploading files to an FTP server. It worked in my development environment but as soon as I deployed my application to a Windows Azure VM it started giving me the following error:
System.Net.WebException: The remote server returned an error: (500) Syntax error, command unrecognized.

Basically, the call to GetRequestStream() method was causing the problem.

To enable System.Net tracing, I added the configuration to my app.config file. This would enable the application to dump necessary debugging messages into a file named “System.Net.trace.log”.

After the first run, I opened the .log file and found this message next to GetRequestStream() call:
500 I won’t open a connection to [my internal IP] (only to [external IP])

Somehow the FTP passive mode transfer was causing this issue. Setting request.UsePassive = true did the trick.

The System.Net tracing configuration that has been added to my app.config file:

The C# code for uploading a file to an FTP server:

Jan 14

Moneris API (Global Error Receipt)

Recently, I was implementing an e-payment solution for a website using Moneris’s PHP API. The configuration process to enable the use of cURL PHP extension went well according to their documentation.  However, the provided API’s code is a total mess. It generates lots of warnings and lacks of necessary data validation. But, still, it gives you some hints to interact with their web services.  Luckily, I found a clean API which I modified to add support for all the returned status code.  Everything worked fine until the moment I receive an error saying “Global Error Receipt”. Uhu? Moneris’s documentation says “You are not connecting to our servers. This can be caused by a firewall or your internet connection”. It turned out that for some reasons, the API was not able to access the cURL certificate which resulted in such error.

May 13

Installing XAMPP on a USB Stick

Sometimes you need to have a portable WAMP development environment. Although many solutions exist (such as WampServer, EasyPHP, etc), I prefer to use XAMPP since it’s loaded with many useful features and packages. Furthermore, XAMPP is provided in a “Portable” lite version which can be found here.

First, select and download an XAMPP Portable Lite zip file and extract it locally on your computer. Then, copy the extracted xampp folder to your USB stick (it might take up to 30 minutes). Once copy is successfully completed and prior to launch XAMPP’s control panel, you need to run the setup_xampp.bat script in order to setup some PHP related environment variables.


Nov 12

How to Create thumbnails or Resize Images on the Fly in PHP

You can simply use PHP GD library but if you are looking for a full featured library, PHP Thumb is what you need. You can generate thumbnails or even manipulate images on the fly. PHP Thumb is a light-weight library and requires PHP 5 and GD 2.0+. CPU utilization and bandwidth are among the things to be considered before using this library. Most of the popular web hosting providers provide a shared hosting service in which they impose CPU throttling. In such service, the usage of CPU is limited and each customer is allowed to use a certain CPU percentage ranging from 10%  to 15%.

If you are planning to generate thumbnails of images that change often and you do not worry about your website’s bandwidth and CPU limit. However, you still can generate such thumbnails in your local test environment and save them to disk and later use them as fixed images.