Absolute and relative paths with FTPWebRequest

March 7th, 2010 Alvos 2 comments

After persuading my client to use explicit SSL :) I ran into another very curious issue that I would like to share with you and maybe it will help you solve a similar problem.

When testing the solution I had to download the files inside a specific path of an FTP location. After downloading the files, I told my client that the solution was working fine but he replied telling me that the files were still in the path. I checked the path using my solution and the files weren’t there! All the files were downloaded to the destination folder and I could see them clearly.

Always blaming the user – as we engineers usually do – I asked my client to share his desktop so that I could see the folder he was looking at and make sure he was looking at the right path. What was my surprise when I saw the “same” folder I was looking at in my computer with a bunch of files pending to be downloaded.

After a couple of minutes scratching my head I realized that we were looking at two different folders using a similar path structure. But how was this possible? I hope I can make it clear enough for you.

Actually, my FTP solution was downloading the files from a relative path. As an example, I was told that after logging to the FTP location, I needed to go to the path “example1/download” to download the files. When I logged in using using my solution I didn’t realize that I was actually being redirected to a folder created for the credentials I was using when logging to the FTP location. As a result, I thought I was accessing the path

ftp://ftplocation.com/example1/download

when I was actually accessing the path

ftp://ftplocation.com/user1/example1/download

because of the automatic redirection to the user folder depending on the credentials used to access the FTP location.

I was having the problem because unfortunately, the FTP location happened to have both paths available – go figure! – and my client was looking at the absolute path – in the example above ftp://ftplocation.com/example1/download.

If you’re having the same problem you need to tell the FTPWebRequest instance that you will be using and absolute path. As the FTWebRequest class has its foundations in the HTTPWebRequest class you are not capable of controlling your FTP session, so you won’t be able to redirect to the root folder – in the example above ftp://ftplocation.com- and redirect to your specific path from there. Fortunately, the geniuses at Microsoft thought of a workaround to tell the FTPWebRequest class you will be using and absolute path instead of your default redirection or relative path.

The following code shows how to do that:

1
2
Uri target = new Uri ("ftp://ftplocation.com/%2fexample1/download");
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(target);

I know “%2f” is an escaped “/” but that’s how the class can tell if it will be using an absolute path instead of a relative one.

It’s simple right? Just add “%2f” before the specific path and you will make sure you are accessing the absolute path. Sometimes you will need  to use a relative path so it’s better if you make that option configurable – maybe a checkbox where you can choose between relative or absolute paths.

Ok, another workaround for the FTPWebRequest class that could save you some trouble.

Cheers!

FTPWebRequest with implicit SSL: NOT POSSIBLE

March 7th, 2010 Alvos 2 comments

Some time ago I had to develop a web FTP solution for a client and as a client’s choice, I had to use ASP.NET 3.5 to do it. I never liked Visual Basic.NET that much so I always use C# when I need to develop .NET applications.

I thought of using the FTPWebRequest class to develop the solution and everything was going fine until I had to use the solution to create a connection to an FTP location that was secured using implicit SSL.

I googled and googled about it and finally I found out that our friends at Microsoft decided NOT to support implicit SSL for the FTPWebRequest class. This is another reason that makes me want to meet the guy who designed this class and slap him in the face. This and the fact that the FTPWebRequest class is based on the HTTPWebRequest class without taking in account that FTP and HTTP are protocols that work in a completely different way, hence, the FTPWebRequest class lacks of a lot of features that could make it a powerful FTP tool.

Having said that, using FTPWebRequest makes it easy to create FTP solutions once you make sure you WON’T need to connect to FTP locations that are secured by implicit SSL. If you are one of the unfortunate souls that need to support this type of security, I’m sorry to say it but you will need to use – as primitive as it sounds – sockets so don’t even bother using FTPWebRequest since you would be doing the work twice.

FTPWebRequest does support explicit SSL so if you  can persuade your client to use explicit SSL in his FTP locations, go for FTPWebRequest since it’s very easy to use.

Cheers!

Using Zend_Db_Select without specifying a database adapter

March 7th, 2010 Alvos No comments

I’ve been working with the Zend_Db_Table object when I want to get one or multiple records from a database table by using fetchAll() or find() methods. The latest versions of Zend Framework – I’m currently using 1.10.2 – come with the following warning: “The API for fetch operations has been superseded to allow a Zend_Db_Table_Select object to modify the query. However, the deprecated usage of the fetchRow() and fetchAll() methods will continue to work without modification.”

The warning says that the deprecated usage of both methods will continue to work without modification but as I’ve had bad times when I’ve trusted these “promises” because deprecated features usually become unmaintained and eventually disappear, I strongly recommend to modify your code to use the latest features offered.

If you follow this link you’ll find how to use the Zend_Db_Select object and in all the examples you need to create and instance of the Zend_Db object in order to use the select object, as in the following example:

1
2
$db = Zend_Db::factory( ...options... );
$select = new Zend_Db_Select($db);

The problem is that most of us never actually create an instance of the Zend_Db object and I don’t recommend it since it’s not configurable at all. As powerful as Zend Framework is, the zf tool it provides, allows us to create database connections that can be used globally and are configurable through the application.ini file. In case you don’t know how to do that here’s an example of how to create a connection to a MySQL database:

How to create a database connection using zf tool

How to create a database connection using zf tool

If you didn’t understand the code in the image you might need to go through the quick start again.

After you have created a database connection using the zf tool, you will be able to use it globally so here’s an example of how to use Zend_Db_Select without having to create an instance of the Zend_Db object:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public function testDBSelect($value)
{
 $select = $this->getDbTable()->select()->from('tbl_example')->where('field = ?', $value);
  
 $stmt = $select->query();
 $result = $stmt->fetchAll();
  
 if (0 == count($result))
 {
  return;
 }
  
 $row = $result[0];
  
 echo($row['Field1']);
 echo($row['Field2']);
}

Basically, you get the instance of the Zend_Db_Select from a Zend_Db_Table object.  The results from the select come in the form of a matrix where the rows are  the records gotten from the table and the columns are the field values  per row.

You would only need to go through the results variable using a basic cycle and access the field values like a normal array $row['field1'], $row['field2'], etc.

Well, for all the ones not being able to solve this problem, there you go.

Cheers!

Why do we have a category for the “geek stuff”?

March 7th, 2010 Alvos No comments

Hello all,

There are thousands of sites that talk about issues or share tutorials that teach you about different technologies and accessing to our site could make you think that it’s just about the same stuff. Trust me, I thought about creating this section a lot of times before actually having the guts to do it.

Actually, I created this section because I’m a guy that spends about 16 hours a day working on something that has to do with sofware development or technology in general and during that time, I have to deal with issues or subjects that aren’t just that easy to resolve just by googling them. Some of them have given me a really hard time and with some I’ve spent about 2 or 3 days before I find the solution that tipically results in a stupid thing.

I’m really busy most of the time and I hate to wait for someone to answer one of my questions in a popular technology forum. Not that I’m ungrateful, but it’s just that it could be much easier if someone had already published what I need. I know most of you agree with me on that :)

After all that being said, I thought about sharing the solution to issues that have given me a hard time so you don’t have to spend more that 10 minutes in something that otherwise could take you hours or days.

I’m not promising detailed tutorials about every topic – I will create them if I have the time – but at least I will publish articles with solutions to questions that are not that easy to find answers for, on the web.

Also, if you have questions or have any issue you’ve spent days on without finding the solution, you are more than welcome to shoot me an email and we can work on it together. Trust me, with all the time I spend in front of the computer, I’ve become very good at solving problems :)

Well, I hope you find something useful inside this section and become a frequent visitor.

Cheers! ;)

Categories: Geek stuff Tags:

Poc Duck (Podilymbus Podiceps)

February 24th, 2010 Mahnu No comments

Maybe it is a name most of the people in the world haven’t and will never get to hear. This beautiful kind of duck became extinct a long time before a lot of us were even born.

It inhabited one of the biggest lakes in Guatemala – a country in Central America . – It’s biology and natural history was studied in the 60’s.

It used to be 20 to 25 inches tall, dark brown plumage with white sidings; down its chest it was gray with white spots, and a neck that changed its color depending on the season, dark brown in the spring and white in the winter. It also had a rare black stripe around its peak.

When reproducing, they used to have 4 to 5 eggs and both parents used to take care of the chicks. They used to feed from crabs.

This species started to diminish in numbers due to the increase in the fishing and tourism. Different kinds of fishes were artificially introduced into their habitat to boost the catch of the fishermen but they didn’t realize that they were creating another competitor that would take the ducks’ way to feed and survive.

Also the ducks started dying as a result of being trapped in the fishing nets and killed by boats.

In 1966, the Ecologist Anne LaBastille started a campaign to save the duck from extinction but her efforts were in vain. Her natural reserve wasn’t enough to counteract the damage we did to their environment and finally in the year 2004 after a study made by the UICN with the sponsorship of BirdLife International, the bird was officially considered extinct.

It is an animal like a lot other that I will never get to meet or even watch on TV. It is sad to think about all we’ve lost and continue losing day after day. I can’t stop thinking about the number of species our children will never get to see or even hear from.

History is all we have left, and we have to learn from it to ensure not only the survival of the wild life but also ours and this planet’s. Thank you Mrs. LaBastille for trying to fight against human nature and I really hope that the future generations don’t look back and hate who we are and what we represented to earth and their future.

I’ll keep posting more of what we’ve lost as a plea for forgiveness to the countless lives of the animals that have fainted in history and in the name of all mankind all I can is, “I’m sorry, we didn’t care”.

May’s giant ant

February 20th, 2010 Mahnu No comments

It isn’t pretty to the eyes I mean, let’s face it; it’s a bug but, is it only a bug? Actually it isn’t.

This bug used to be the mark of an era that does not exist anymore and guess who’s responsible for this loss? We are.

I remember when I was a little kid that, I and my friends liked May as that was the month that came with a rain of this particular kind of bugs, a hilarious and exciting sight for our eyes. They flooded the streets like a live mantle and we used to enjoy playing with them though some car owners used to get upset as their automobiles were almost fully covered with these insects since the early mornings.

May’s giant ants were not only a fun thing to play with for us the once “little kids of our country”, and an annoying thing for the drivers and traffic, but they were also a particular part of May’s commerce and eating supplements. Believe it or not these bugs could and were highly consumed as they were very rich in nutrients and some say “tasty” – fortunately or not, I never got to taste one of these little creepy insects. I never gathered the gust to try one. – “They taste like peanuts”, my mom used to say.

I remember the first May these insects didn’t show up. We were noticing from years before that they arrived later and later in the month every year. But that particular May – I don’t remember the year – they didn’t. We all started asking our friends if they found or at least had a glimpse of one and we all said no. However, nobody paid attention to that as it was a “little” and “insignificant” thing that didn’t affect our daily living.

Surprising the entire country and mostly the people living in the capitol city, May’s giant ants showed up in “June” for the first time ever, which is a little bit ironic considering the popular name of the ants – nobody ever even tried to change that name to “June’s giant ants”. – That continued to happen the subsequent years until last year – 2009 – which for some reason or better said our fault; they didn’t show up at all.

I’m not a biologist or a scientist, and I have not been able to find any recent information about this giant ants, but I can tell that in my personal experience I didn’t get to see any and that made me think a lot about the damage we’re doing to this planet and the number of species that are going extinct due to us.

These little and magnificent creatures had a biological clock that made them get out of their hideouts every year at the same exact time but, we messed up so much with their environment that we changed that clock. We changed it to the point of telling them not to get out anymore as the weather wasn’t good for them; that made them stop feeding and reproducing themselves, and now they stopped visiting us.

I wonder how many other species, traditions, pleasures, etc. we will void our children to enjoy if we keep treating this planet with unbelievable disrespect and careless attitude.

I’m just looking forward for this years May or June – maybe July – to see if these now missed creatures forgive us for neglecting their way of living and pay us a visit. I sure hope to see at least one.

Categories: Environmental Tags: , , , , , ,

The end of the world, or not?

February 13th, 2010 Mahnu No comments

A few weeks ago I was thinking about starting a blog but I didn’t know what to write about. I thought to myself, “You know a lot about movies; why don’t you write about them?” But that’s something so burned out that nobody is going to read what I write as I know someone already does it a lot better so; suddenly today something came up to my mind and it is something I want to share with you all.

Three weeks ago I had my first week of vacations in over three and a half years. I was so tired about my job that I just wanted to sleep. The first two days I did so, nothing else. But on the third day I decided to watch some TV and the first channel that was in it was playing a documentary about nature and how we’re recklessly destroying it.

I followed that documentary for days as it was divided in different chapters and after watching them all I thought, “Oh my God, we’re killing this planet.”

I found this website one day while I was wandering around the internet and the information it displayed was very interesting but also frightening. Check it yourselves and you’ll see what I’m talking about http://www.worldometers.info/. I hope it had also a count for the days we have left on this planet, or the days we have left until we completely destroy it.

I know it is more than known by a huge part of the world’s population that global warming is a reality but, I’ve closely seen the changes we’ve done to our environment as a result of the careless sense of appreciation we have for all living beings, animal and vegetable.

More than 15 years ago I remember swimming in the nearest lake to the city in my country. It was clean and beautiful. We had a lot of tourists visit it due to its incomparable tranquility and natural richness. 10 years ago it was impossible not to be afraid of even being touched by the water as it was completely polluted, dirty and unhealthy. Though you still could see people fishing on it you could only think of the damage they were doing themselves by eating those very contaminated fish. But that’s all they had to live day by day.

More than 10 years ago I remember swimming in this other beautiful lake, not so close to the city but you really wanted to go there as it was priceless to feel its water touching your body, as if someone was holding you gently. Now, if I turn my TV on and watch the local channels for sure I’ll see some adds advertising the lake, asking for help to the whole country to save it, as it is infested by this very poisonous seaweed that is literally killing the lake and all the life in it. You cannot swim in it now. But some – not a lot – people are still fighting to save it.

If both cases happened only in my country, knowing that the UN has 192 nations as members, how much similar cases do we have in the entire world? You may think that I wrote “much” as a grammatical mistake but actually I did it on purpose as I know that the damage we’re doing to this planet is countless.

I really want to thank the small group of humans that are fighting to defend this planet, saving species, protecting forests, the sea, etc. By this I’m not thanking the world known organization of extremists that actually do more harm than good; but all the unknown saints that are actually fighting for their lives and ours and to give humanity at least a couple of days more of clean air.

Before I used to think, “when I have lot of money the first thing I’ll do is buy an expensive car as I love them”, even when I know that it has been proven that in my country we cannot make a full use of them as we do not have the roads to be able to ride them well; they’re merely a luxury item, an item that marks a status.

A few days I came to the conclusion that I don’t want a luxury car anymore even believing that I will get to be wealthy, as it is not something that I need but something I want. The only way we’re going to live longer is if we start thinking about what we need to about what we want. Therefore I will use a lot of my wealth to help not only the planet but also the people that are suffering due to how greedy we are. I will no longer wish for a 10 acre house or a $100,000.00 car. I will only get what I need to live, that’s it. That way when I have kids I will leave for them something to dream for, or at least save for them some water to drink.

I thought one day, “I wish I had a lot of money to be able to do something to help this planet and the people leaving on it as others do”, but then I realized that I don’t need it. If I get at least one person to read my blog day after day I’ll be doing my part to create awareness amongst humanity.

Consider this note a start for a blog dedicated only to nature. I’ll be publishing every story I live or find about the damage we’re doing to this planet and how we can contribute to help it, as after all, we’re only going to be helping ourselves and our children.

Categories: Environmental Tags: